resize and thumbnail in one command

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
estrolz

resize and thumbnail in one command

Post by estrolz »

Hello together!

Is it possible to create a resized picture and a thumbnail in one command?

Now I do it like this:

Code: Select all

convert -thumbnail 80x80 test.jpg thumb.jpg
convert -resize 150x150 test. jpg resized.jpg
But I want to do it like the following, to get better performance, because I have to call the commands from php via "exec" command:

convert test.jpg TO thumbnail AND TO resized.jpg
?

Thanks a lot for your help.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: resize and thumbnail in one command

Post by Bonzo »

There has been at least 2 threads posted about this over the last 6 months http://redux.imagemagick.org/discourse- ... =1&t=10360

Code: Select all

<?php
exec("convert input.jpg \( +clone -thumbnail 1024x768> -write image_large.jpg +delete \) \( +clone -thumbnail 800x600> -write image_medium.jpg +delete \)\( +clone -thumbnail 300x300! -write image_small.jpg +delete \)-thumbnail 100x100! image_tiny.jpg");
?>
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: resize and thumbnail in one command

Post by anthony »

See Mutliple Writes in IM Examples
http://imagemagick.org/Usage/files/#write
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
JAM3SoN

Re: resize and thumbnail in one command

Post by JAM3SoN »

Hi! I don't want to create new thread. I want to know the fastest way to do this:

convert filename.jpg

create thumbnail with width 580px, 250px, 100px and square 64x64px from middle of small image.

I want to do it on-the-fly while uploading images in php (not bigger than 1MB) by ajax uploader.

Is it possible to use imagemagick in this way? How can I achieve the fastest speed?(I will use imagemagick only for this purpose).

What will be performance if hundreds of people will use uploader at the same time?

Some expert ideas?;) Thoughs? Did anyone do something similar?

Thanks a lot in advance, it is important for me.
JAM3SoN

Re: resize and thumbnail in one command

Post by JAM3SoN »

Nobody knows?:(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize and thumbnail in one command

Post by fmw42 »

Please clarify. Do you want one command to generate all of the image at each size: 580, 250,100 and center 64 from 100? Or do you want one command to generate only one of the above sizes? Also do you want the image resized separate from the thumbnails and if so at what size?

The former can be done (assuming you want a square image even if distorted) by:

convert image.png \
\( -clone 0 -thumbnail 580x580! -write image580.png +delete \) \
\( -clone 0 -thumbnail 250x250! -write image250.png +delete \) \
\( -clone 0 -thumbnail 100x100! -write image100.png \) \
+clone -delete 0-1 -gravity center -crop 64x64+0+0 image64.png


I don't know about doing it while uploading (probably need to save it as a temporary) nor performance with multiple people running it.

I don't know if this will help with efficiency but you might want to look at:
http://www.imagemagick.org/Usage/files/#massive

The other thing to consider is to put your image into a memory mapped format when you upload it. See: mpr and mpc formats

http://www.imagemagick.org/Usage/files/#mpr
http://www.imagemagick.org/Usage/files/#mpc

So this may be faster (you would have to do some time tests, although my tests seem to show the above is slightly faster)

convert image.png -write mpr:image +delete \
\( mpr:image -thumbnail 580x580! -write image580.png \) \
\( mpr:image -thumbnail 250x250! -write image250.png \) \
\( mpr:image -thumbnail 100x100! -write image100.png \) \
+clone -delete 0-2 -gravity center -crop 64x64+0+0 image64.png
JAM3SoN

Re: resize and thumbnail in one command

Post by JAM3SoN »

Thanks for very kind and comprehensive answer. To be clear, I want just one command. When uploading, file sent from user is stored on temporary place... Then I should work with temporary file assigned in variable on my server. Need one command to create these image sizes.(Also I have script to get image dimensions because of what thumbnails it have to create - not doing 580px thumb for 300px image).

I really don't understand this:
Also do you want the image resized separate from the thumbnails and if so at what size?
From my temporary file I need to create images width specified widths and save original image(classified as original). Hope I said everything, if not, just ask ;)

Thanks for help again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize and thumbnail in one command

Post by fmw42 »

My confusion has to do with your original statement about "Is it possible to create a resized picture and a thumbnail in one command?" There is a difference between just resizing and creating a thumbnail. The latter strips other non-image data like header information. See -resize and -thumbnail. Thus my question about whether you wanted just thumbnails or also resized images as well as the thumbnails.

see

http://www.imagemagick.org/script/comma ... php#resize
http://www.imagemagick.org/script/comma ... #thumbnail


The example I sent only creates thumbnails from the original image. It does not create simple resized images nor resized images in addition to the thumbnails.
JAM3SoN

Re: resize and thumbnail in one command

Post by JAM3SoN »

Ok, I've played with my command and achieved what I want:

convert upload/384sk01dg8/9t11vmh45m.jpg -write mpr:image +delete \( mpr:image -thumbnail 480 -write upload/384sk01dg8/9t11vmh45m_480.jpg \) ( mpr:image -thumbnail 250 -write upload/384sk01dg8/9t11vmh45m_250.jpg \) ( mpr:image -thumbnail 100x100! -write upload/384sk01dg8/9t11vmh45m_100.jpg \) ( mpr:image -thumbnail 64x64! -write upload/384sk01dg8/9t11vmh45m_64.jpg \)

Is it possible to make this command faster? How?

Moreover, how can I find out speed of this command?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize and thumbnail in one command

Post by fmw42 »

I don't know how you can make it faster, if that is even possible, but you can get speed information by adding time before your command

time convert ....


P.S. My examples above were just one command line. It just had line continuations using the \ character to make it more readable.
Post Reply