What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file? I have some scanned images that I want to display smaller on web pages and, although gimp will do it, it does seem a bit of a sledgehammer to crack a nut.
It would be nice to be able to just say something like:-
someProgram -x 400 -y 200 <old.jpg >new.jpg
Going further, is it easy/possible to change the size of an image according to the size of the browser window being used? I use a 1600x1200 display at home so a 400x200 image will be quite small really but if anyone looks at the same page on (say) 800x600 it's going to be a bit on the large size.
On Thu, 8 Dec 2005, Chris Green wrote:
What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file? I have some scanned images that I want to display smaller on web pages and, although gimp will do it, it does seem a bit of a sledgehammer to crack a nut.
It would be nice to be able to just say something like:-
someProgram -x 400 -y 200 <old.jpg >new.jpg
Hi Chris
Have a look at mogrify. It's part of ImageMagick
HTH
Chris
Chris Green wrote:
What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file? I have some scanned images that I want to display smaller on web pages and, although gimp will do it, it does seem a bit of a sledgehammer to crack a nut.
It would be nice to be able to just say something like:-
someProgram -x 400 -y 200 <old.jpg >new.jpg
Going further, is it easy/possible to change the size of an image according to the size of the browser window being used? I use a 1600x1200 display at home so a 400x200 image will be quite small really but if anyone looks at the same page on (say) 800x600 it's going to be a bit on the large size.
Chris,
How about ImageMagick's convert program:
http://www.imagemagick.org/script/convert.php
convert old.jpg -size 400x200 new.jpg
HTH,
Jim / /
On 08-Dec-05 Jim Rippon wrote:
Chris Green wrote:
What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file? I have some scanned images that I want to display smaller on web pages and, although gimp will do it, it does seem a bit of a sledgehammer to crack a nut.
It would be nice to be able to just say something like:-
someProgram -x 400 -y 200 <old.jpg >new.jpg
Going further, is it easy/possible to change the size of an image according to the size of the browser window being used? I use a 1600x1200 display at home so a 400x200 image will be quite small really but if anyone looks at the same page on (say) 800x600 it's going to be a bit on the large size.
Chris,
How about ImageMagick's convert program:
http://www.imagemagick.org/script/convert.php
convert old.jpg -size 400x200 new.jpg
And don't forget to have a look at all the options in "man comvert" for enhancing/smoothing/etc (you may need to look up "man ImageMagick" to get explanations of some of them).
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 08-Dec-05 Time: 12:11:05 ------------------------------ XFMail ------------------------------
(Ted Harding) wrote:
On 08-Dec-05 Jim Rippon wrote:
Chris Green wrote:
What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file? I have some scanned images that I want to display smaller on web pages and, although gimp will do it, it does seem a bit of a sledgehammer to crack a nut.
It would be nice to be able to just say something like:-
someProgram -x 400 -y 200 <old.jpg >new.jpg
Going further, is it easy/possible to change the size of an image according to the size of the browser window being used? I use a 1600x1200 display at home so a 400x200 image will be quite small really but if anyone looks at the same page on (say) 800x600 it's going to be a bit on the large size.
Chris,
How about ImageMagick's convert program:
http://www.imagemagick.org/script/convert.php
convert old.jpg -size 400x200 new.jpg
And don't forget to have a look at all the options in "man comvert" for enhancing/smoothing/etc (you may need to look up "man ImageMagick" to get explanations of some of them).
Ted.
E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 08-Dec-05 Time: 12:11:05 ------------------------------ XFMail ------------------------------
main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
My "man convert" page says "For more information about the convert command, point your browser to" with links to the online docs. "man ImageMagick" doesn't come up with much more in the way of an explanation of the options available.
"convert --help", however, displays all the options available along with brief descriptions, but beware this is many, many pgup's long!
Jim
On 08-Dec-05 Jim Rippon wrote:
(Ted Harding) wrote:
Chris,
How about ImageMagick's convert program:
http://www.imagemagick.org/script/convert.php
convert old.jpg -size 400x200 new.jpg
And don't forget to have a look at all the options in "man comvert" for enhancing/smoothing/etc (you may need to look up "man ImageMagick" to get explanations of some of them).
Ted.
My "man convert" page says "For more information about the convert command, point your browser to" with links to the online docs. "man ImageMagick" doesn't come up with much more in the way of an explanation of the options available.
"convert --help", however, displays all the options available along with brief descriptions, but beware this is many, many pgup's long!
Jim
Thanks for correcting my misleading message! (This was based on the memory that you look at ImageMagick for the available formats).
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 08-Dec-05 Time: 12:45:35 ------------------------------ XFMail ------------------------------
(Ted Harding) Ted.Harding@nessie.mcc.ac.uk writes:
On 08-Dec-05 Jim Rippon wrote:
How about ImageMagick's convert program:
http://www.imagemagick.org/script/convert.php
convert old.jpg -size 400x200 new.jpg
And don't forget to have a look at all the options in "man comvert" for enhancing/smoothing/etc (you may need to look up "man ImageMagick" to get explanations of some of them).
The -quality option is often worth setting when working with JPEGs - the default can be a bit low for some purposes IME. But remember that you're not going to "get back" anything lost in previous JPEG compression.
Chris Green chris@areti.co.uk
What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file?
netpbm is one: jpegtopnm old.jpg | pnmscale .... | pnmtojpeg >new.jpg
Others have suggested imagemagick, which can also do it.
Going further, is it easy/possible to change the size of an image according to the size of the browser window being used? I use a 1600x1200 display at home so a 400x200 image will be quite small really but if anyone looks at the same page on (say) 800x600 it's going to be a bit on the large size.
You can use relative sizes and let the browser scale them, but browsers seem bad at scaling images. Another possibility is to prepare resized images and then use a little javascript to replace the ones used by default with the closest one to the appropriate size, in a similar way to how rollovers work.
Hope that helps,
Chris Green wrote:
What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file?
As with others here I was going to suggest imageMagick, but since they have I won't.
Instead I have a related question: Is there a way with imageMagick (or something else, for that matter, but commandline based) to shoehorn an image into a fixed size and shape, using a specified background colour where the height:width ratio of the image differs from the desired destination size?
Eg: I have a 300x300 box to put a 400x600 image into. It would need reducing to 200x300 (so it fits the 300x300), then centred over (say) a black 300x300 rectangle to create the final image. Ideally the background colour, and alignment over the background, would be optional, but black and centred would normally be fine.
Whenever I've used convert I've been unable to achieve this (I get the 200x300 bit easily, but that's where I get stuck). Given the myriad of options I've never been convinced the option I want isn't lurking there somewhere.
Incidentally, when using these functions from within a web script, it's worth noting that: - Taking an uploaded image (ie uploaded to /tmp somewhere) and moving it to its new home, changing to an image format you're happy with and rescaling it is trivial in a single step with convert and much easier than checking whether a usable JPEG or unsusable TIFF has been uploaded, how big it is, etc. - These tools can usually work from a URL as the source, so you can convert from an online image to a resized converted local image in one step without first downloading it. Therefore we often give the option from the web upload page to enter the URL of an image to use instead of actually uploading it; very little is required in the way of code changes.
The message 439954E7.9010806@quarella.co.uk from Mark Rogers mark@quarella.co.uk contains these words:
Chris Green wrote:
What's a quick and easy tool for resizing (as in changing the default screen size) of a Jpeg file?
As with others here I was going to suggest imageMagick, but since they have I won't.
Instead I have a related question: Is there a way with imageMagick (or something else, for that matter, but commandline based) to shoehorn an image into a fixed size and shape, using a specified background colour where the height:width ratio of the image differs from the desired destination size?
Yes.
Eg: I have a 300x300 box to put a 400x600 image into. It would need reducing to 200x300 (so it fits the 300x300), then centred over (say) a black 300x300 rectangle to create the final image. Ideally the background colour, and alignment over the background, would be optional, but black and centred would normally be fine.
Yes.
Whenever I've used convert I've been unable to achieve this (I get the 200x300 bit easily, but that's where I get stuck). Given the myriad of options I've never been convinced the option I want isn't lurking there somewhere.
You can do it quite easily with html...
Anthony Anson wrote:
Instead I have a related question: Is there a way with imageMagick (or [...]
Yes.
Excellent!
Eg: I have a 300x300 box to put a 400x600 image into. It would need [...]
Yes.
I'm getting really excited now, the anticipation is killing me...
Whenever I've used convert I've been unable to achieve this (I get the [...]
You can do it quite easily with html...
Cheat!
It's not always appropriate to do it that way, eg if I'm importing images into third party templates where I don't have access to the templates, or if the printing behaviour matters.
But well done for spotting the workaround I currently use!
Mark Rogers wrote:
Eg: I have a 300x300 box to put a 400x600 image into. It would need reducing to 200x300 (so it fits the 300x300), then centred over (say) a black 300x300 rectangle to create the final image. Ideally the background colour, and alignment over the background, would be optional, but black and centred would normally be fine. Whenever I've used convert I've been unable to achieve this (I get the 200x300 bit easily, but that's where I get stuck). Given the myriad of options I've never been convinced the option I want isn't lurking there somewhere.
I've been lurking for a while (so by way of introduction - "hi all"). I thought I'd pipe up as this is a subject dear to my heart - I am a bit of a photo-obsessive and have over 11,000 photos on my website - most of which have been processed via Perl scripts using ImageMagick.
Here's a Perl example of implementing a composite of two images - your background (created on-the-fly) and your thumbnail:
########################################################## #!/usr/bin/perl #
use Image::Magick;
# create background...
$image = Image::Magick->new; $image->Set( size=>'300x200' ); $image->ReadImage( 'xc:black' );
# read image to add on top...
$image2 = Image::Magick->new; open ( IMAGE, 'myImageToAdd.jpg' ); $image2->Read( file=>*IMAGE );
$width = $image2->Get('width'); $height = $image2->Get('height');
if ( $width > $height ) {
# landscape print "landscape... "; $newwidth = 300; $ratio = $height / $width; $newheight = int( $mainsize * $ratio ); } else {
# portrait print "portrait... "; $newheight = 200; $ratio = $width / $height; $newwidth = int( $mainsize * $ratio ); }
$image2->Resize( width=>$newwidth, height=>$newheight, filter=>'Hamming' );
$image->Composite( image=>$image2, compose=>'Atop' ); $image->Set( quality=>"89" ); # set output JPEG quality $image->UnsharpMask( radius=>0.6, sigma=>0.7, amount=>0.7, threshold=>0.02 ); # took me /ages/ to get this right $image->Strip(); # remove space-hogging EXIF data, etc
$image->Write( 'test.jpg' ); #######################################################
Or something like that. You can fiddle around with the position your second image ends up with attributes such as Geometry - look at http://www.imagemagick.org/script/perl-magick.php and the section on "Composite".
Of course, as another poster pointed out, you could save a bit of bandwidth by wrapping your image in a suitable background-coloured table cell, <div> or <span>. Personally, I'm a big fan of cropped (as opposed to windowed) thumbnails - even though you do occasionally chop people's heads off!
Simon
Mark Rogers mark@quarella.co.uk
Instead I have a related question: Is there a way with imageMagick (or something else, for that matter, but commandline based) to shoehorn an image into a fixed size and shape, using a specified background colour where the height:width ratio of the image differs from the desired destination size?
I think you need to use the < operator on the resize and mogrify's -background option.
If you want to use netpbm, look at pamscale and pnmpaste.
Thanks for noting about convert and uploaded files. Good ideas.
Hope that helps,