Page 1 of 1

resize to original image size

Posted: 2012-01-01T10:28:39-07:00
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?

Re: resize to original image size

Posted: 2012-01-01T12:25:49-07:00
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

Re: resize to original image size

Posted: 2012-01-02T23:56:55-07:00
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