Resize Photo Help

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
luwenbin

Resize Photo Help

Post by luwenbin »

I am implementing a funcion using MagickCore to resize the photo which are uploaded by uesrs to 3 sizes, 400x600,200x300,100x150. I write the code as follow:

Code: Select all

char *blob = xxxxx //get from http request
size_t length = xxxx//get from http request
ImageInfo *blob_info = CloneImageInfo((ImageInfo *)NULL);
Image *blob_image = BlobToImage(blob_info, blob, length, exception); 
Image *resize_image1 = ResizeImage(image, 400, 600, LanczosFilter, 1.0, exception);
Image *resize_image2 = ResizeImage(image, 200, 300, LanczosFilter, 1.0, exception);
Image *resize_image3 = ResizeImage(image, 100, 150, LanczosFilter, 1.0, exception);
But according to the increase of users, the speed of resize images should be improved. I found that most of photos are jpg format, and for jpg files, it seems that we can directly convert it to N/8 sizes(N=1,2,4). The problem I met is I don't know which API I should use to directly convert to 8/N size. could anyone give me some helps? I tried the following code which can archive what I want, but I don't know whether it is correct.

Code: Select all

char *blob = xxxxx //get from http request
size_t length = xxxx//get from http request
ImageInfo *blob_info = CloneImageInfo((ImageInfo *)NULL);
Image *blob_image = BlobToImage(blob_info, blob, length, exception); 
Image *resize_image1 = ResizeImage(image, 400, 600, LanczosFilter, 1.0, exception);
size_t new_length = 0;
char *new_blob = ImageToBlob(blob_info, resize_image1, new_length, exception);
char size[10] = "200x300";
blob_info->size = malloc(strlen(size)+1);
strcpy(blob_info->size, size);
Image *resize_image2 = BlobToImage(blob_info, new_blob, new_length, exception); 
strcpy(blob_info->size, "100x150");
Image *resize_image3 = BlobToImage(blob_info, new_blob, new_length, exception); 
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Resize Photo Help

Post by magick »

Our blob is the ImageMagick logo (e.g. logo:). This code returns 640x480 as expected:
  • blob_image = BlobToImage(blob_info, blob, 43693, exception);
    printf("%d %d\n",blob_image->columns,blob_image->rows);
And this code returns 160x120 as expected:
  • blob_info->size = ConstantString("64x64");
    blob_image = BlobToImage(blob_info, blob, 43693, exception);
    printf("%d %d\n",blob_image->columns,blob_image->rows);
To get the exact size your are looking for you then follow with a call to ResizeImage().

We are using ImageMagick 6.5.3-0, the latest release.
Post Reply