Adding a drop Shadow with phMagick

August 9, 2009 by nuno costa 7 comments

phMagick :: Drop Shaddows

 

You can add drop-shadows even to complex images, you can also specify shadow color, offset and opacity

 

Default drop-shadow

$phMagick = &new phMagick('original.png');
$phMagick->setDestination('shaddow2.png');
 ->dropShaddow();

 

Original Image Result

 

 

Custom drop shaddow (blue shaddow, 10px offset, 60% opacity)

$phMagick = &new phMagick('original.png');
$phMagick->setDestination('shaddow3.png');
 ->dropShaddow('#00f', 10, 60);

 

Original Image Result

 

Complex Image Drop-shadow

$phMagick = &new phMagick('original.png');
$phMagick->setDestination('shaddow.png') 
 ->dropShaddow();

 

Original Image Result

 

7 comments so far Add Your Comment

  1. by Beto Lima on November 23 2009 at 18:01

    Hi, i from brasil and i have a doubt. First i want to explain that i don’t know english, perfectly. Ok let’s go. for my situation i need to use with dropshadow but using more than one image. I want to show in browser many images of products of my site using dropshadow. Is this possible? Need i to change the script? Thank you.
    PS: Enjoying, tell me if my english is well!!!

  2. by nuno costa on November 24 2009 at 12:17

    Hello Beto,

    Your english is fine to me.

    You can do that but on file at a time, that is for each image you want to display you must first create the shadow and then show it as a regular image (< img src= …).
    I would advice you to name your new images as dropshadow_image_name that way you can check if the image was already created so you don't have to create the images again

    Olá Beto,
    Podes fazer isso sem problemas, mas tem que ser imagem a imagem.
    As imagems novas são guardadas no disco e podes mostra-las como uma imagem normal com a tag img

    O que costumo fazer nestes casos e gravar a nova imagem com um prefixo como dropShadow_ antes do nome.
    Por exemplo se a imagem original se chamar 123.jpg a nova vai se chamar dropShadow_123.jpg assim posso verificar se ja criei a dropshadow antes e não tenho que a criar de novo, porque fazer isso a cada pedido da pagina vai tornar o teu site lento

    Um abraço de Portugal

  3. by mac97000 on December 3 2009 at 11:44

    Hello,
    I’m sorry but I think that in the first and second example you have one more ” ; ” at the end.

    $phMagick->setDestination(‘shaddow3.png’); <- this one

    ————-

    Bonjour,

    je viens de découvrir votre excellent script.

    En essayant différente proposition je pense que vous avez un point virgule de trop dans le premier et le second exemple à la fin de la ligne "destination".

    Cordialement Manuel

  4. by mac97000 on December 3 2009 at 11:52

    Sorry …

    You write “dropShaddow” with 2 “d” for the example …

    But the class function is “dropShadow” with only one “d”.

    Best regards Manuel

  5. by nuno costa on December 15 2009 at 16:51

    @ mac97000

    That example comes from the old version, where dropshadow was misspelled

    Thanks for noticing the syntax error, I will correct it

  6. by Daniel Iser on January 25 2011 at 15:24

    Ive got this working perfectly now with my personal website screenshot server to create thumbnails for my link directory im developing. Problem im running into is that the background color when creating the drop shadow is set to a color instead of transparent and i dont use a white background. You can try it your self at sandbox(dot)wizardinternetsolutions(dot)com/links/addurl/

    my images are in png format to begin with and i dont change that so transparency should be ok. Is there a way to change the background color for the drop shadow effect? Changing the drop shadow color had no bearing for me.

  7. by Daniel Iser on January 25 2011 at 16:04

    Ok so after some reading up on IM and looking through your code i can achieve a matching background by changing the second -background under your dropShadow function to the color im using. this is a temporary fix for now but id like to be able to use them with any background as im trying to develop this as a plugin for clients and their backgrounds will inevitably be different colors.

More from francodacosta.com

© francodacosta.com - All rights reserved