[solved] blur and resize after upload

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
bfred
Posts: 3
Joined: 2017-05-29T21:11:27-07:00
Authentication code: 1151

[solved] blur and resize after upload

Post by bfred » 2017-05-29T21:18:53-07:00

Hi!

I'm writing a web app using Laravel and was wondering if it was possible with ImageMagick to do the following:
  • upload a 4/3 aspect ratio image
  • create a blur version of it
  • split that blur version in 2 vertically and spread it on both sides of the upload image to change its aspect ratio ratio to 3/2
So if you upload a 400x300 pixel image you end up with a 450x300 pixel size image where both sides have a blur version of each side "underneath it".

I hope my description was clear enough. And if it is possible, what would be the functions to use?
Thank you very much.
Last edited by bfred on 2017-05-29T23:33:48-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: blur and resize after upload

Post by fmw42 » 2017-05-29T22:21:30-07:00

ImageMagick can only process once the file is uploaded. I am not sure what you want for the result.
  • upload a 4/3 aspect ratio image
  • create a blur version of it
  • split that blur version in 2 vertically and spread it on both sides of the upload image to change its aspect ratio ratio to 3/2
So if you upload a 400x300 pixel image you end up with a 450x300 pixel size image where both sides have a blur version of each side "underneath it".
So you start with a 400x300 (WxH) image. If you blur it, it is still only 400x300. If you resize the input to 450x300, then it is wider than before and perhaps you want to split the image in left and right sides; otherwise, there is no point is splitting the top and bottom, since the height has not changed?


Input (400x300):
Image

So which do you want?

Code: Select all

convert barn2.png \
\( -clone 0 -resize 450x300! -blur 0x3 \) \
\( -clone 0 -crop 100x50% +repage \) \
\( -clone 1 -clone 2 -gravity north -compose over -composite \
-clone 3 -gravity south -compose over -composite \) \
-delete 0-3 barn2_comp1.png
Image

In the above case, there is really no point in splitting the resized image. It just needs to be inserted into the center of the blurred image as follows:

Code: Select all

convert barn2.png \
\( -clone 0 -resize 450x300! -blur 0x3 \) \
+swap -gravity center -compose over -composite \
barn2_comp1b.png
The result should be the same as the previous code.

Or do you want:

Code: Select all

convert barn2.png \
\( -clone 0 -resize 450x300! -blur 0x3 \) \
\( -clone 0 -crop 50x100% +repage \) \
\( -clone 1 -clone 2 -gravity west -compose over -composite \
-clone 3 -gravity east -compose over -composite \) \
-delete 0-3 barn2_comp2.png
Image

If I have misunderstood, please clarify.

Please see viewtopic.php?f=1&t=9620

ImageMagick can

1) resize an image -- see http://www.imagemagick.org/Usage/resize/

2) split into two parts -- see http://www.imagemagick.org/Usage/crop/#crop

3) composite each part over some background image -- see http://www.imagemagick.org/Usage/compose/#compose and http://www.imagemagick.org/Usage/layers/#convert

If you can provide and example or drawing of what you want and and explanation, then we can provide the specific code to help you do that.

Please provide your platform/OS since ImageMagick code may be OS dependent and if you have installed ImageMagick, then what version you. are using.

bfred
Posts: 3
Joined: 2017-05-29T21:11:27-07:00
Authentication code: 1151

Re: blur and resize after upload

Post by bfred » 2017-05-29T23:07:39-07:00

Hi and thanks!

So yes aspect ratio is w/h for me too ;-) I basically want to resize a normal digital camera image into a DSLR image with the extended sides (what's missing) filled by a blur extension of the photo rather than a plain color. And no I do not want to distort the photo neither.
Maybe this sample attached image (wrong ratios) would give you an idea of what I'm trying to achieve.

http://imgur.com/a/GBnBV

Thank you
ps: didn't see your images on the first read. So yes that would be the 2nd example. Does it actually resize the image too, or just blur the sides?

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: blur and resize after upload

Post by fmw42 » 2017-05-29T23:23:34-07:00

didn't see your images on the first read. So yes that would be the 2nd example. Does it actually resize the image too, or just blur the sides?
The second example with the blur in the middle was created by:

line1 -- read the input
line2 -- copy it and resize to 450x300 and blur
line3 -- copy the input and crop into left and right sides
line4 -- insert the left part onto the blurred image at the left side
line5 -- insert the right part onto the blurred image at the right side
line6 -- delete the temporary copies and write the output.

Code: Select all

convert barn2.png \
\( -clone 0 -resize 450x300! -blur 0x3 \) \
\( -clone 0 -crop 50x100% +repage \) \
\( -clone 1 -clone 2 -gravity west -compose over -composite \
-clone 3 -gravity east -compose over -composite \) \
-delete 0-3 barn2_comp2.png

bfred
Posts: 3
Joined: 2017-05-29T21:11:27-07:00
Authentication code: 1151

Re: blur and resize after upload

Post by bfred » 2017-05-29T23:29:59-07:00

Super! Thanks a lot!

Post Reply