Page 1 of 1
ConvertImageCommand Oddness
Posted: 2010-10-06T00:19:43-07:00
by 3DTOPO
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!
Re: ConvertImageCommand Oddness
Posted: 2010-10-06T10:13:51-07:00
by el_supremo
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
Re: ConvertImageCommand Oddness
Posted: 2010-10-06T14:37:01-07:00
by 3DTOPO
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.
Re: ConvertImageCommand Oddness
Posted: 2010-10-07T02:24:27-07:00
by 3DTOPO
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.
Re: ConvertImageCommand Oddness
Posted: 2011-09-21T07:49:14-07:00
by fulvio
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.
Re: ConvertImageCommand Oddness
Posted: 2011-09-22T19:31:02-07:00
by glennrp
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.
Re: ConvertImageCommand Oddness
Posted: 2011-09-22T20:32:37-07:00
by fulvio
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.