iPhone - ConvertImageCommand(), MagickWand() in Objective-C.
Posted: 2011-09-20T23:14:52-07:00
I have the following batch file that works successfully in Windows using "convert.exe"
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:
Any help would be greatly appreciated. Thanks in advance.
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
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];
}