Page 1 of 1

resize and thumbnail in one command

Posted: 2008-03-18T03:08:23-07:00
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.

Re: resize and thumbnail in one command

Posted: 2008-03-18T08:26:25-07:00
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");
?>

Re: resize and thumbnail in one command

Posted: 2008-03-18T16:43:08-07:00
by anthony
See Mutliple Writes in IM Examples
http://imagemagick.org/Usage/files/#write

Re: resize and thumbnail in one command

Posted: 2008-04-02T13:43:19-07:00
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.

Re: resize and thumbnail in one command

Posted: 2008-04-13T02:27:14-07:00
by JAM3SoN
Nobody knows?:(

Re: resize and thumbnail in one command

Posted: 2008-04-13T21:04:08-07:00
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

Re: resize and thumbnail in one command

Posted: 2008-04-14T14:37:51-07:00
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.

Re: resize and thumbnail in one command

Posted: 2008-04-14T16:22:07-07:00
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.

Re: resize and thumbnail in one command

Posted: 2008-05-04T01:45:43-07:00
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?

Re: resize and thumbnail in one command

Posted: 2008-05-04T17:43:07-07:00
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.