Page 1 of 1

Cant get Image Drop Shadow to Work

Posted: 2017-03-21T15:45:53-07:00
by coderanger
I am having a really hard time trying to get drop shadows for an image to work; i thought it would be quite easy but no matter what i do nothing works.

This is the code i am trying to use with the following image Image

Code: Select all

using( MagickImage image = new MagickImage( "d:\\mainimage.jpg" ) )
using( var savedShadowImageStream = new FileStream( "d:\\shadow-imagemagik.jpg", FileMode.Create ) )
{
    image.Strip();
    image.Quality = 100;
    image.Resize( 2000, 0 );

    MagickImage shadow = image.Clone();
    shadow.Quality = 100;

    // shadow( x, y, sigma, alpha, colour )
    // basically i dont get any sort of blurred shadow
    // x and y dont seem to do anything at all
    // sigma seems to be shadow size and not the amount of blur
    // alpha doesnt seem to do anything either
    shadow.Shadow( 10, 10, 0.5, new Percentage( 80 ), MagickColor.FromRgb( 127, 127, 127 ) ); // this makes the shadow size tiny
//    shadow.Shadow( 10, 10, 20, new Percentage( 80 ), MagickColor.FromRgb( 127, 127, 127 ) ); // this makes the shadow size bigger, but why its supposed to be the blur size

    shadow.Composite( image, CompositeOperator.Replace );

    shadow.Write( savedShadowImageStream, MagickFormat.Jpeg );
}
I even tried an example posted in these forums and that didnt work either, all I get is the following look: Image

When what i want is:
Image

Can anyone help please; i have spent all day on this and am not really any further forward.

Re: Cant get Image Drop Shadow to Work

Posted: 2017-03-21T16:14:26-07:00
by snibgo
Why are you writing to JPEG? That format removes transparency, so you can't see the effect of the shadow.

While you are developing, I suggest you should write to a format that has transparency, and doesn't mangle the pixels, such as PNG.

As a further clue, your "desired output" has clearly been flattened against a white background. I don't see that step in your code.

Re: Cant get Image Drop Shadow to Work

Posted: 2017-03-21T16:18:09-07:00
by coderanger
Of course; good point!! Thanks