Asked  1 Year ago    Answers:  5   Viewed   22 times

i am looking for a way to add a drop shadow to an image using php. before you answer or vote to close: i am not looking to do this using css or html. i want to generate an image file. this is not a duplicate of this question nor this one.

i am looking for a very specific effect. for example, given this input image:

i want to produce the following image:

tl;dr: this image above was generated using photoshop's drop shadow effect. i want a look very similar to that. for reference, here's the settings our design team used. ideally, i'd have similar control in my code for angle, distance, opacity, etc:

i have full access to our debian-linus-based servers, so any gd or imagemagick solution will work. as will any foss linux software solution, although i'd prefer a way to do it with im or gd as those are already installed and don't require new software to be installed.

the shadow must be able to be placed on a transparent, non-rectangular png!

i'm asking the question mainly because the scripts and solutions i have found on the web either only produce rectangular shadows, look like total poo, or just plain don't work at all.



you're not going to be able to do this in php without building in a full edge-detector algorithm and significant processing overhead. look into using gimp with some script-fu, and let it do the hard work for you.

Thursday, April 1, 2021

the solution was the following:

    if ($width/$height > $this->maxwidth/$this->maxheight) {
      // then resize to the new height...
                $command .= ' -resize "x'.$this->maxheight.'"';

                // ... and get the middle part of the new image
                // what is the resized width?
                $resized_w = ($this->maxheight/$height) * $width;

                // crop
                $command .= ' -crop "'.$this->maxwidth.'x'.$this->maxheight.'+'.round(($resized_w - $this->maxwidth)/2).'+0" +repage';
            } else {
              $command .= ' -resize "' . $this->maxwidth . 'x"';
              $resized_h = ($this->maxwidth/$width) * $height;

                // crop
                $command .= ' -crop "'.$this->maxwidth.'x'.$this->maxheight.
                             '+0+'.round(($resized_h - $this->maxheight)/2).'" +repage';
Saturday, May 29, 2021

this code snippet should help explain the three different buttons you can use:

    alertdialog = new alertdialog.builder(this).create();

    alertdialog.settitle("dialog button");

    alertdialog.setmessage("this is a three-button dialog!");

    alertdialog.setbutton(alertdialog.button_positive, "button 1 text", new dialoginterface.onclicklistener() {

      public void onclick(dialoginterface dialog, int id) {


    } }); 

    alertdialog.setbutton(alertdialog.button_negative, "button 2 text", new dialoginterface.onclicklistener() {

      public void onclick(dialoginterface dialog, int id) {



    alertdialog.setbutton(alertdialog.button_neutral, "button 3 text", new dialoginterface.onclicklistener() {

      public void onclick(dialoginterface dialog, int id) {


Sunday, August 8, 2021

i would lean towards imagemagick as far as image quality goes. it seems to produce considerably sharper/higher-quality images than gd2 (at the expense of larger filesize.)

imagemagick is also not bound by php's memory limit.

Monday, August 9, 2021

in the end i decided to just use background png images with the shadows, and apply them with a subclass for uinavigationbar and uitoolbar which implemented the drawrect method (for the background image) and the sizethatfits method to resize the navigation bar. here is the final product (the button hides the bars):

here are the methods i implemented in each subclass:

 - (void)drawrect:(cgrect)rect {
   uiimage *image = [[uiimage imagenamed:@"bargloss-withshadow.png"] retain];
   [image drawinrect:rect];
   [image release];

- (cgsize)sizethatfits:(cgsize)size {
    cgsize newsize = cgsizemake(320,60);
    return newsize;

please note that i also made the bars black translucent in ib so that the content flowed under them.

Friday, September 10, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :