ConvertImageCommand Oddness

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

ConvertImageCommand Oddness

Postby 3DTOPO » 2010-10-06T00:19:43-07:00

Greetings,

I am using ImageMagick 6.6.4-8 on iPhone OS 4.0.

I am using the ConvertImageCommand() function with success in the iPhone simulator, but the same exact code is failing on a physical iPhone.

The args that I am using are:

Code: Select all

char *argv[] = { "convert", filePath, "-colorspace", "gray", clutPath, "-clut", outputPath, NULL };


The error:

Code: Select all

reason: missing an image filename `/private/var/mobile/Applications/5C553FF0-A25E-49B1-AE43-7F6E3FF19202/tmp//out.png' @ convert.c/ConvertImageCommand/2946
description: (null)
code: 0


'filePath' is a valid path to an input.png, 'clutPath' is a valid path to a png, and 'outputPath' is a valid, writable path to a new out.png.

The assertion is being thrown apparently because out.png is NULL, but it should be NULL as the file is to be created from the convert operation.

As I said, this same code is working in the iPhone Simulator, and the same flags/files works with the convert command line tool on Mac OS X.

Furthermore, if I just remove the clut flag and clut png file, it successfully creates out.png as a new grayscale image (as expected), both in the Simulator and on the iPhone.

This behavior is repeatable.

Any help would be greatly appreciated! I am stumped!

el_supremo
Posts: 987
Joined: 2005-03-21T21:16:57-07:00

Re: ConvertImageCommand Oddness

Postby el_supremo » 2010-10-06T10:13:51-07:00

When IM complains about the output file being missing, it usually means that one (or more) of the required input files is missing. My guess is that somehow either filePath or clutPath is a null string.

Pete

3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

Re: ConvertImageCommand Oddness

Postby 3DTOPO » 2010-10-06T14:37:01-07:00

They are not null strings though - thus is confirmed as they are printed to my log with printf.

Does the same thing even if I hard code them. I mainly used vars here because it is easier to read.

3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

Re: ConvertImageCommand Oddness

Postby 3DTOPO » 2010-10-07T02:24:27-07:00

OK, so I have it figured out.

Even though checking for the clut file reported it existed and that it was readable (using NSFileManager), apparently for some reason unknown to me it was not readable by 'convert'. The clut was in the main bundle (resource) folder (which is accessible by the app). I wrote a copy of the image file to the tmp directory (the same directory I am using for input/output image) and it works!

So while this is likely not a bug with ImageMagick, the error message was not at all helpful in narrowing down the cause, in fact it lead me to believe there was a problem with the output file based on the message. It would have been very helpful if it had reported that the clut was not readable....

Thanks for listening.

fulvio
Posts: 8
Joined: 2011-09-20T17:59:18-07:00
Authentication code: 8675308

Re: ConvertImageCommand Oddness

Postby fulvio » 2011-09-21T07:49:14-07:00

3DTOPO wrote:OK, so I have it figured out.

Even though checking for the clut file reported it existed and that it was readable (using NSFileManager), apparently for some reason unknown to me it was not readable by 'convert'. The clut was in the main bundle (resource) folder (which is accessible by the app). I wrote a copy of the image file to the tmp directory (the same directory I am using for input/output image) and it works!

So while this is likely not a bug with ImageMagick, the error message was not at all helpful in narrowing down the cause, in fact it lead me to believe there was a problem with the output file based on the message. It would have been very helpful if it had reported that the clut was not readable....

Thanks for listening.


Are you able to provide working Objective-C code for ConvertImageCommand()?

I'm having a lot of trouble with my code here:

Code: Select all

- (void)convertImage {
    MagickWandGenesis();
    magick_wand = NewMagickWand();
    //UIImageJPEGRepresentation([imageViewButton imageForState:UIControlStateNormal], 90);
    NSData * dataObject = UIImagePNGRepresentation([UIImage imageNamed:@"iphone.png"]);
    MagickBooleanType status;
    status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }

    // Resize image.
    ImageInfo *imageInfo = AcquireImageInfo();
    ExceptionInfo *exceptionInfo = AcquireExceptionInfo();

    // Get image from bundle.
    char *input_image = strdup([[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]);
    char *output_image = strdup([[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]);
    char *argv[] = { "convert", input_image, "-resize", "100x100", output_image, NULL };

    // ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *);
    status = ConvertImageCommand(imageInfo, 5, argv, NULL, exceptionInfo);

    free(input_image);
    free(output_image);

    if (status == MagickFalse) {
        ThrowWandException(magick_wand); // Always throws an exception here...
    }

    size_t my_size;
    unsigned char * my_image = MagickGetImageBlob(magick_wand, &my_size);
    NSData * data = [[NSData alloc] initWithBytes:my_image length:my_size];
    free(my_image);
    magick_wand = DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    UIImage * image = [[UIImage alloc] initWithData:data];
    [data release];

    [imageViewButton setImage:image forState:UIControlStateNormal];
    [image release];
}


http://stackoverflow.com/questions/7480 ... tive-c-usi

I'm not quite sure I've implemented it properly.

User avatar
glennrp
Posts: 859
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: ConvertImageCommand Oddness

Postby glennrp » 2011-09-22T19:31:02-07:00

Is your PNG really a PNG? On iPhone, PNGs are converted by pngcrush (which isn't really pngcrush) to a non-PNG format that pretends to be PNG.
Normal PNG applications such as ImageMagick will reject them.

fulvio
Posts: 8
Joined: 2011-09-20T17:59:18-07:00
Authentication code: 8675308

Re: ConvertImageCommand Oddness

Postby fulvio » 2011-09-22T20:32:37-07:00

glennrp wrote:Is your PNG really a PNG? On iPhone, PNGs are converted by pngcrush (which isn't really pngcrush) to a non-PNG format that pretends to be PNG.
Normal PNG applications such as ImageMagick will reject them.


Yes, it's a PNG.


Return to “Bugs”

Who is online

Users browsing this forum: No registered users and 4 guests