Page 1 of 1

iPhone - ConvertImageCommand(), MagickWand() in Objective-C.

Posted: 2011-09-20T23:14:52-07:00
by fulvio
I have the following batch file that works successfully in Windows using "convert.exe"

Code: Select all

@echo off

set SOURCE=input_file.jpg

del output_file.jpg
del source_copy.jpg

conv %SOURCE% -fill "#fff8f2" -colorize 100%% fill.jpg

copy %SOURCE% source_copy.jpg

conv %SOURCE% -modulate 100,0,100 -|^
conv - source_copy.jpg -compose overlay -composite -|^
conv source_copy.jpg - -compose dissolve -define compose:args=37,100 -composite -|^
conv - -modulate 100,70,100 +level 3.5%%,100%% -|^
conv - -channel red -level 0%%,89%% +level 9%%,100%% -|^
conv - -channel green +level 3.5%%,100%% -|^
conv - -channel blue -level 0%%,93%% +level 4.7%%,100%% -|^
conv - -brightness-contrast -5x3 -|^
conv fill.jpg - -compose multiply -gravity center -composite -|^
conv - -level 3.5%%,100%%,0.91 +level 2.7%%,100%% -|^
conv - -channel red +level 3.5%%,100%% -|^
conv - -channel green -level 0%%,87%% +level 1%%,100%% -|^
conv - -channel blue -level 0%%,100%%,0.94 +level 7%%,100%% -|^
conv - -brightness-contrast -1x0 output_file.jpg

del source_copy.jpg
del fill.jpg
At the moment I'm using the following code in Objective-C to achieve the same effect, however I'm a little stuck when it comes to the ConvertImageCommand() method:

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);
    }

    // Get image from bundle.
    const char *input_image = [[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String];
    const char *output_image = [[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String];

    const char *argv[] = { "convert", input_image, "-resize", "100x100", output_image, NULL };
    // ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *);
    status = ConvertImageCommand(AcquireImageInfo(), 4, (char**)argv, NULL, AcquireExceptionInfo());

    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }
   
    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];
}
Any help would be greatly appreciated. Thanks in advance.

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Posted: 2011-09-21T04:41:47-07:00
by magick
The argc parameter is an integer that specifies the number of arguments in the argv[] array. The argv[] array contains the command line arguments (e.g. argv[0] = "convert", argv[1] = "image.png", argv[2] = "output.jpg").

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Posted: 2011-09-21T04:49:31-07:00
by fulvio
magick wrote:The argc parameter is an integer that specifies the number of arguments in the argv[] array. The argv[] array contains the command line arguments (e.g. argv[0] = "convert", argv[1] = "image.png", argv[2] = "output.jpg").
Okay, I've updated my code to a resize example, however would you be able to modify it to perform what my batch file performs? Also I'm not quite sure what's means to go into the metadata array (in my case "argc[]").

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Posted: 2011-09-21T04:50:27-07:00
by magick
Metadata is returned in that array. You can keep it null if you don't care about it.

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Posted: 2011-09-21T04:53:28-07:00
by fulvio
magick wrote:Metadata is returned in that array. You can keep it null if you don't care about it.
Okay, I see. Do you think you'd be able to give me a hand modifying my array to contain what's in my batch file? I'm not quite sure how to create one whole line with all of my properties. Also, I wasn't sure what to put as the integer either (I've placed 2...)?