ImageMagick with iPhone

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
isoyaboy
Posts: 2
Joined: 2014-04-17T03:08:35-07:00
Authentication code: 6789

ImageMagick with iPhone

Post by isoyaboy »

Hi

I have been trying to figure out how to convert jpg to tiff on an iPhone for 3 days.

The following command gives me the desired results.

Code: Select all

convert input.JPG -strip -density 200 -resize 1000x486\! -define tiff:rows-per-strip=1 -compress Group4 output.tif
I have tried the following code and it works for iOS 7.0.6 but not any other iOS versions. I am not even sure if the code below is correct. I have read pretty much all the threads related to iPhones on here but I still can't figure it out.

Code: Select all

-(UIImage *)convertImageToTiff
{
    // Get image from bundle.
    char *inputPath = strdup([self.inputImagePath UTF8String]);
    char *outputPath = strdup([self.outputImagePath UTF8String]);
    
    char *argv[] = {"convert", inputPath, "-strip", "-density", "200", "-resize", "1000x486\\!", "-define", "tiff:rows-per-strip=1", "-compress", "Group4", outputPath, NULL};
    
    MagickCoreGenesis(*argv, MagickFalse);
    MagickWand *magick_wand = NewMagickWand();
    NSData * dataObject = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:self.inputImagePath], 1.0f);
    MagickBooleanType status;
    status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
    if (status == MagickFalse) {
        NSLog(@"Error %@", magick_wand);
        
    }
    
    ImageInfo *imageInfo = AcquireImageInfo();
    ExceptionInfo *exceptionInfo = AcquireExceptionInfo();
    
    int elements = 0;
    while (argv[elements] != NULL)
    {
        elements++;
    }
    
    // ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *);
    status = ConvertImageCommand(imageInfo, elements, argv, NULL, exceptionInfo);
    
    if (exceptionInfo->severity != UndefinedException)
    {
        status=MagickTrue;
        CatchException(exceptionInfo);
    }
    
    if (status == MagickFalse) {
        fprintf(stderr, "Error in call");
        ThrowWandException(magick_wand); // Always throws an exception here...
    }
    
    UIImage *convertedImage = [UIImage imageWithContentsOfFile:self.outputImagePath];
    
    return convertedImage;
}
isoyaboy
Posts: 2
Joined: 2014-04-17T03:08:35-07:00
Authentication code: 6789

Re: ImageMagick with iPhone

Post by isoyaboy »

Just adding to the above.

The code above will produce the correct image on iOS 7.0.6, but for all other iOS versions it will produce a file, but when trying to open the file I am prompted with an image corrupted message.
Post Reply