resize to original image size

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
Balduin
Posts: 3
Joined: 2012-01-01T09:35:50-07:00
Authentication code: 8675308

resize to original image size

Post by Balduin »

Hello,
I'm trying to do a fast blur operation by resizing an image (layer) smaller and then back to the exact original size. Since I apply the resize command to images of different sizes, I can't set a specific size in the argument for resize.

I tried it without success:

Code: Select all

convert 0.jpg -set origsize "%Wx%H" \( +clone -scale 20% -resize "%[origsize]" \) -composite 1.jpg
It seems key/value in strings are only resolved for format:
> convert 0.jpg -set origsize '%Wx%H' -format '%[origsize]!' info:
> 205x128!
The same command should run on both Linux and Windows, so the following does not help:
> convert 0.jpg -scale 20% -resize `convert 0.jpg -format '%Wx%H!' info:` 1.jpg

Is it possible at all to use the key/value as argument for resize? (Did I just do it wrong?)
Alternatively, is there an option that stretches the layer to the canvas size?
Last edited by Balduin on 2012-01-01T13:18:36-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize to original image size

Post by fmw42 »

I know that does not work with -resize as it is not sensitive to computations. I tried doing it with -distort resize, but it ignored it. Anthony can answer this best.

In the mean time, just set up a variable for your dimensions. Then pass that to your processing command as

size=`convert image -format "%wx%h" info:`
convert 0.jpg \( +clone -scale 20% -resize $size \) -composite 1.jpg

If you really want it in one command
convert 0.jpg \( +clone -scale 20% -resize $(convert 0.jpg -format "%wx%h" info:) \) -composite 1.jpg

The above is unix. If on windows see http://www.imagemagick.org/Usage/windows/ for syntax differences
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: resize to original image size

Post by anthony »

-distort resize also will not use '%' escapes for the same reason -resize does not. They both use 'geomtery arguments' in whcih '%' is already defined as a special character. It is a major problem for IMv6 with no easy solutions.
http://www.imagemagick.org/Usage/basics/#arg_geometry

For 'bluring' form of resize however I would at least use a Gaussian-like filter
http://www.imagemagick.org/Usage/resize ... r_gaussian

This will ensure you do not get 'rings' but do get perfectly round 'dots'.

For some examples where resize is actually used as a fast 'bluring' function see the later part of...
Sparse Color Shepards, a Blur Alternative
http://www.imagemagick.org/Usage/canvas/#sparse_blur
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply