Create several thumbnails from a single original image

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
hiigara
Posts: 4
Joined: 2011-12-17T13:59:09-07:00
Authentication code: 8675308

Create several thumbnails from a single original image

Post 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?
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Create several thumbnails from a single original image

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
hiigara
Posts: 4
Joined: 2011-12-17T13:59:09-07:00
Authentication code: 8675308

Re: Create several thumbnails from a single original image

Post by hiigara »

Thanks. CloneMagickWand is exactly what I was looking for.
Post Reply