Problem with polaroid effect shadows

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
gazchap
Posts: 6
Joined: 2009-03-01T02:58:21-07:00

Problem with polaroid effect shadows

Post by gazchap »

I was using IM 6.3.5, but last night changed to the latest version on the website to see if the behaviour was different, to no avail.

I'm trying to replicate the polaroid effect seen in Anthony's IM Examples, but without using the -polaroid operator as this does too much - I don't want the slight curl in the picture/shadow for example.

So, using a JPEG image as input, I'm using the following command:

Code: Select all

convert "photo.jpg" -matte -thumbnail "420x>" \
-bordercolor white -border 5 \
-bordercolor grey60 -border 1 \
-background black \( +clone -shadow 60x4+4+4 \) +swap \
-background white -flatten \
jpeg:"-"
This is the result of that command:
Image

Not quite what I intended! If I take out the line with the shadow operator on it (the whole line) the picture becomes this:
Image

I want the soft shadow to just appear around the edges of this, like on the IM v6 Examples page :)

Any help appreciated :)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problem with polaroid effect shadows

Post by Bonzo »

This works for me with 6.4.0

Used php on my local server :) If I escaped the ( and ) I had the same result as you - may be a windows problem as on my host I have to escape the ( and ).

Code: Select all

<?php

$cmd = "convert attach2.jpg -matte -thumbnail \"420x>\" ".
" -bordercolor white -border 5  ".
" -bordercolor grey60 -border 1  ".
" -background black ( +clone -shadow 60x4+4+4 ) +swap  ".
" -background white -flatten  ";

exec("convert $cmd  gazchap.jpeg");

?>

<img src="gazchap.jpeg">
Image
gazchap
Posts: 6
Joined: 2009-03-01T02:58:21-07:00

Re: Problem with polaroid effect shadows

Post by gazchap »

Aah, brilliant :) Ta muchly, I'm using a Windows host for testing too - weird that it does that.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problem with polaroid effect shadows

Post by anthony »

NOTE that your shadow offset is not correct. The blur of a shadow image extends in all directions and even further than than the offset you provided.

To do this properly replace -flatten with -layers merge +repage that will get you a correct offset result regardless of what direction the shadow offset falls.


See IM Examples, Shadows, for more details
http://www.imagemagick.org/Usage/convolve/#shadow
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
gazchap
Posts: 6
Joined: 2009-03-01T02:58:21-07:00

Re: Problem with polaroid effect shadows

Post by gazchap »

What version did -shadow and +clone become available? And +swap for that matter?

I'm using 6.4.8 at home and on the live server they're only running 6.0.7 (and can't upgrade it apparently) and the script doesn't work until I comment out the +clone line.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problem with polaroid effect shadows

Post by Bonzo »

Try this code I used on another site:

Code: Select all

/* Removed as the IM version is toooooo old
// Large image with drop shadow
exec("convert $value -matte -resize 560x450 \( +clone -background black -shadow 90x3+15+15 \) +swap -gravity northwest -geometry -3-3 -composite -background white -flatten +repage $photo");
*/

// Large image with drop shadow
// Resize original and save a temp version
exec("convert $value -resize 560x450 tmp/temp.png");
// Use the temp image to create the shadow
exec("convert tmp/temp.png -depth 8 -threshold 0 -colorize 18,18,18 -negate -bordercolor white -border 20x20 -gaussian 0x3 -shave 15x15 tmp/shadow.png"); 
// Put the temp image over the shadow and save
exec("composite tmp/temp.png -gravity center -geometry -10-10 tmp/shadow.png $photo");
// cleanup temp files
unlink('tmp/temp.png');
unlink('tmp/shadow.png');
Could probably be condensed bit if required and lose at least 1 tempory image although you will need to add your borders.

Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problem with polaroid effect shadows

Post by anthony »

gazchap wrote:What version did -shadow and +clone become available? And +swap for that matter?

I'm using 6.4.8 at home and on the live server they're only running 6.0.7 (and can't upgrade it apparently) and the script doesn't work until I comment out the +clone line.
+clone +swap and parentheses which were added in the very early days of IM, which is why you have then in 6.0.7. Shadowing was a common problem, but complex to work out, and was added much later, about 2005 or so (some where in v6.2 I think)

The -layers merge was a even later addition at v6.3.6-2

I really suggest that you have your ISP update as 6.0.7 is now ridiculously old.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply