Uploading pictures to Facebook - iphone

I am writing an app that publishes pictures on Facebook using facebook-ios-sdk, but everytime I upload a picture, it's displayed with the wrong orientation on my album. Here's the code I am using, note that I account for the orientation on the second line:
ALAssetRepresentation *rep = [currentAsset defaultRepresentation];
UIImage *img = [UIImage imageWithCGImage:[rep fullResolutionImage] scale:[rep scale] orientation:[rep orientation]];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
[pictureCaptionTextView text], #"caption",
nil];
[facebook requestWithMethodName: #"photos.upload"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
[img release];
Does anyone know what's going on? Should I pass the orientation when uploading it?

Have you tried using different photos, or are you testing on the same images each time? Sometimes an image will have EXIF data that will tell image programs to rotate it; it could be either that facebook is honoring EXIF data that your local app isn't and thus rotating or it could be that locally your program is displaying it rotated and facebook isn't.
Try viewing your photo in a few different browsers, and even better try downloading a photo from facebook and then re-uploading it =]

I finally figure this out thanks to this link.
The trick is that UIImageView automatically rotates the image correctly but the raw data is always on the default camera orientation (landscape, top to the right), so you need to adjust accordingly.
Bonus: this method resizes the image if you need to.

Related

display and create gif image on iPhone

I am googling for the answer from last few hours. I know that Apple and Facebook do not support gif images, I wants to display and create gif image in an iPhone App, I find the alternate solution that make the image sequence and give animation. I wants to create the GIF image from these images and post on Facebook wall.
When I was googling about Facebook and Apple, it shows 2 years old answers. May be now apple and Facebook changed their policies, Is this possible to create GIF image on iPhone App and post to it on Facebook?
According to this stack overflow question here does Apple support gif images?
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"image1.gif"],
[UIImage imageNamed:#"image2.gif"],
[UIImage imageNamed:#"image3.gif"],
[UIImage imageNamed:#"image4.gif"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];
I've been able to create animated gifs on iOS using ImageMagick. There are a number of tutorials out there. Here is one. And here is ImageMagick compiled for iOS.
What I wasn't able to sort out (due to time) was how to get the benefit of compression by using palettized images and other gif compression methods. That wold be something to look into as I found the images I was able to create were quite large.

Facebook Photo Size in iOS sdk

Right now with the Facebook iOS sdk, I am pulling images off the wall. but I need to analyze the photo and determine the height and width of the photo.
How would I go about doing this?
I know that this is an old question which has been answered, but since the accepted answer is very unclear and because this might help others that have the same problem as you had:
Given that the images that you pull off the wall are turned into UIImage objects before you display them, then you can just do the following to easily get the height and width of each object:
Full code example:
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:yourimageurlhere]];
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
[imageData release];
NSLog(#"Height : %0.1f", image.size.height);
NSLog(#"Width : %0.1f", image.size.width);
when you issue a call to GraphAPI photo object, you get dimensions in the response: https://graph.facebook.com/98423808305
is it what are you looking for?

iphone: UIImagePickerController how to get the thumbnail for the picker control

Hello I need to use the uiimagepickercontroller to get the photo from the photo library in IOS 3. I managed to get the original image and custom coding to generate the thumbnail from the original image.
Is there a way of fetching the thumbnail that was used in the UIImagePickerController? I can generate thumbnail from original image but it will slow down the whole process. At the time, is there a way of saving the url of the original image. At the moment, I am just create a new image and saved on a temporary folder for later app to upload the server. The process is too slow since I need to generate thumbnail as well as creating the original image.
in ios 3.0 , their is no direct way to get thumbnail, you have to do custom coding to get thumbnail .
from version 4.0 we have ALAssetsLibrary.
ALAssetsLibrary *assetslibrary = [self defaultAssetsLibrary];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
CGImageRef thumbnailRef = [myasset thumbnail]; //gives thumbnail
}
[assetslibrary assetForURL:asseturl resultBlock:resultblock failureBlock:^(NSError *error) {
//handle error
}];
but cons of above method is if used declined access to library then you have to handle error and again get thumbnail again with custom coding .
please update if you have find any better method .

Can't get [ALAsset thumbnail] for picture, but works for video

I 'm trying to display the thumbnail for a picture or video my app takes. It works perfectly for video but for a picture it simply doesn't show anything. This is the code I used:
[assetImageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
I also tried this as an alternative but also nothing:
ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[assetRepresentation fullScreenImage]];
[assetImageView setImage:image];
Any ideas what may be going on?
The problem wasn't on this method, it was before. I wasn't retaining the object asset so it got lost before reaching this line. Thanks for the help.
Could you please show us the result of NSLog(#"asset:%#", asset) when the problem occurs? Your 1st code works fine under my environment.

posting UIImage to facebook along with other text

i'm trying to post an image on facebook using the following code.
FBStreamDialog* dialog ;
if([FBSession session].isConnected)
dialog = [[[FBStreamDialog alloc] initWithSession:[FBSession session]] autorelease];
else
dialog = [[[FBStreamDialog alloc] initWithSession:session] autorelease];
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"%#\",\"media\":[{\"type\":\"image\",\"src\":\"%#\"}]}", strEventStatus,eventImg];
[dialog show];
Does the media tag have any other property apart from src which would take and image in form of NSData? how do i post the image otherwise?
While you are linking the attachment property for a Image the source should be a URL.. I dont think You can post a UIImage by using attachment.. One solution is you can have a webservice for posting the image in your server and then give that URL when you are posting.
I dont know which Facebook API you are using..
This what i did to upload a image by using Facebook Graph API
UIImage *img = [UIImage imageNamed:#"myImage.png"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
//facebook is a facebook Obj which I initialized before
[facebook requestWithMethodName:#"photos.upload"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
I have no knowledge of the Facebook API you are using, but it would seem Image SRC would imply that the image is already somewhere on the web.
Have you considered uploading the image to a server somewhere and using the SRC of the image as a URL?
I hope this helps!
You can directly take a UIimage and upload via the code used by BuildSucceeded, you no longer need to forward the image to a server and link via URL. You can also call the image from a UIimageview, camera or library.