Page 1 of 1

ImageMagick with iPhone

Posted: 2014-04-17T03:42:58-07:00
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;
}

Re: ImageMagick with iPhone

Posted: 2014-04-17T03:49:24-07:00
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.