Hi,
I've just added the iOS ImageMagick by Claudio to my project and was wondering if there are any examples for using MagickWand in iOS? I'm just trying to do simple stuff like:
convert pug.png -ordered-dither h4X4a pug2.png
and am not really too versed in C. Is it possible to take a UIImage and add effects to it using ImageMagick iOS?
Thanks.
Example of iOS Usage
-
- Posts: 15
- Joined: 2014-04-14T11:40:01-07:00
- Authentication code: 6789
-
- Posts: 15
- Joined: 2014-04-14T11:40:01-07:00
- Authentication code: 6789
Re: Example of iOS Usage
Done a little searching around and so far able to come up with:
Where originalImage is a UIImage. I'm applying this and it's doing nothing to the image. I wonder if my issue is with putting the args incorrectly, or if not extracting the resulting image correctly?
UPDATE: Edited my code to include the exception handling code in the example. Now am getting: UnrecognizedDitherMethod `h4x4a'.
Code: Select all
MagickWandGenesis();
MagickWand *wand = NewMagickWand();
NSData *data = UIImagePNGRepresentation(self.originalImage);
MagickReadImageBlob(wand, [data bytes], [data length]);
int arg_count = 3;
char *args[] = { "-ordered", "-dither", "h4x4a", NULL};
ImageInfo *image_info = AcquireImageInfo();
ExceptionInfo *exception = AcquireExceptionInfo();
MagickBooleanType status = ConvertImageCommand(image_info, arg_count, args, NULL, exception);
if (exception->severity != UndefinedException)
{
status = MagickTrue;
CatchException(exception);
}
if (status == MagickFalse)
{
NSLog(@"FAIL");
}
size_t my_size;
unsigned char * my_image = MagickGetImageBlob(wand, &my_size);
NSData *outData = [[NSData alloc] initWithBytes:my_image length:my_size];
free(my_image);
self.imageView.image = [[UIImage alloc] initWithData:outData];
image_info=DestroyImageInfo(image_info);
exception=DestroyExceptionInfo(exception);
DestroyMagickWand(wand);
MagickWandTerminus();
UPDATE: Edited my code to include the exception handling code in the example. Now am getting: UnrecognizedDitherMethod `h4x4a'.
Last edited by ImageGandalf on 2014-04-17T12:14:12-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Example of iOS Usage
At the command-line, "-ordered-dither" is a single token, with no spaces. I don't know if this is your problem.
snibgo's IM pages: im.snibgo.com
-
- Posts: 15
- Joined: 2014-04-14T11:40:01-07:00
- Authentication code: 6789
Re: Example of iOS Usage
Thanks for taking a look. I've actually tried it the way you mentioned and when I do the status comes back as false. When I split them as above, the exception gets thrown, so not sure what that means.snibgo wrote:At the command-line, "-ordered-dither" is a single token, with no spaces. I don't know if this is your problem.
I've also tried doing:
Code: Select all
char *args[] = {"-posterize", "4", NULL};
Code: Select all
ImageInfo *image_info = AcquireImageInfo();
Code: Select all
MagickReadImageBlob(wand, [data bytes], [data length]);
-
- Posts: 15
- Joined: 2014-04-14T11:40:01-07:00
- Authentication code: 6789
Re: Example of iOS Usage
Actually updated some of my code, I was failing to get the resulting image from the blob. Now if I substitute ConvertImageCommand with
that actually works. However, still having trouble getting ConvertImageCommand to work. A guy on Stackoverflow recommended to use:
But this gives the same result as ConvertImageCommand. Has anyone had success before executing either CovertImageCommand or MagickCommandGensis on iOS?
Code: Select all
MagickBooleanType status = MagickPosterizeImage(wand,6,MagickFalse);
Code: Select all
MagickBooleanType status = MagickCommandGenesis(image_info, ConvertImageCommand, arg_count, args, NULL, exception);
-
- Posts: 15
- Joined: 2014-04-14T11:40:01-07:00
- Authentication code: 6789
Re: Example of iOS Usage
Well I found an example on Stackoverflow where a guy lists his command like this:
Since I'm not grabbing my image from the bundle, I wonder, what would I put for the inputImage and outputImage parameters? I've tried NULL and it doesn't work.
Code: Select all
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 };