Page 1 of 1

Create several thumbnails from a single original image

Posted: 2011-12-18T18:26:36-07:00
by hiigara
I want to create thumbnails of different sizes from the same source image. I am able to create a single thumbnail with this code:

Code: Select all

g_Magickwand = NewMagickWand();
MagickReadImage( g_Magickwand, "test.jpg" )
MagickResizeImage( g_Magickwand, "150", "100", LanczosFilter, 1.0 );
MagickWriteImage( g_Magickwand, "test_tn1.jpg" );
g_Magickwand = DestroyMagickWand( g_Magickwand );
Now I want to create another thumbnail from test.jpg:

Code: Select all

...
MagickResizeImage( some_wand, "300", "200", LanczosFilter, 1.0 );
MagickWriteImage( some_wand, "test_tn2.jpg" );
...
I could create another wand and call MagickReadImage again, but since this is for a busy internet server, there is probably a more efficient way of doing it, without reading the disk again. How can I keep "test.jpg" in memory while creating several thumbs?

Re: Create several thumbnails from a single original image

Posted: 2011-12-18T19:24:19-07:00
by el_supremo
If you want 300x200 and 150x100 you can create the 300x200 first, write it, and then just cut the image in half and write that.
If you want to (or have to) start from the original image each time, use CloneMagickWand to create a copy of the original wand.
e.g. do something like this pseudo-code:

Code: Select all

image_wand = readimage();
    clone_wand = CloneMagickWand(image_wand);
    do a resize of clone_wand
    write clone_wand
    destroymagickwand(clone_wand);

    clone_wand = CloneMagickWand(image_wand);
    do a different resize of clone_wand
    write clone_wand
    destroymagickwand(clone_wand);

etc.
Pete

Re: Create several thumbnails from a single original image

Posted: 2011-12-20T13:15:04-07:00
by hiigara
Thanks. CloneMagickWand is exactly what I was looking for.