Page 1 of 1
Adding shadow to 2 combined images
Posted: 2018-03-10T16:43:02-07:00
by stealthrt
Been trying for awhile now trying to get a shadow using the following code:
Code: Select all
using (MagickImage image = new MagickImage(@"C:\Users\David\Pictures\YnTf9.png"))
{
MagickImage _shadow = new MagickImage(bitmap);
using (IMagickImage backgroundImg = image.Clone())
{
backgroundImg.Blur(0, 5);
backgroundImg.Crop(400, 300, Gravity.Center);
backgroundImg.RePage();
image.Resize(0, 300);
_shadow.Resize(0, 300);
_shadow.Shadow(10, 10, 0.8, (Percentage)80, MagickColor.FromRgb(0, 0, 0));
backgroundImg.Composite(_shadow, Gravity.Center, CompositeOperator.SrcOver);
backgroundImg.Composite(image, Gravity.Center, CompositeOperator.SrcAtop);
backgroundImg.Write(@"C:\Users\David\Pictures\NEW.png");
}
}
But the outcome looks like it originally did to begin with:
And what I am looking to accomplish with the code above is:
Anyone able to help me out?
Re: Adding shadow to 2 combined images
Posted: 2018-03-10T17:27:46-07:00
by snibgo
Where does "bitmap" come from? A shadow must be a shadow of something (ie opaque pixels) but I can't see what that "something" is.
While you develop this, I suggest you write _shadow to a file. Then you can more easily find where the problem is.
Re: Adding shadow to 2 combined images
Posted: 2018-03-10T20:33:29-07:00
by fmw42
I suggest you work in the command line first and +write tmpX.png at each step to see what it is doing. Then convert that to .NET.
Try this (I create a black in white mask image that I blur, then multiply it by the blurred cropped background image. Then I overlay the resized image onto the center of that).
Code: Select all
convert YnTf9.png \
\( -clone 0 -blur 0x10 -gravity center -crop 400x300+0+0 +repage \) \
\( -clone 0 -resize x300 \) \
\( -clone 1 -fill white -colorize 100 \) \
\( -clone 2 -fill black -colorize 100 \) \
\( -clone 3,4 -gravity center -compose over -composite -blur 0x15 -level 40x100% \) \
-delete 0,3,4 \
\( -clone 0,2 -gravity center -compose multiply -composite \) \
-delete 0,2 +swap \
-gravity center -compose over -composite \
result.png
Re: Adding shadow to 2 combined images
Posted: 2018-03-11T15:51:17-07:00
by stealthrt
Hum.. that seems to come out just my own does. Its looks just like the normal image.
Re: Adding shadow to 2 combined images
Posted: 2018-03-12T10:01:28-07:00
by stealthrt
Any input on the command line issue?
Re: Adding shadow to 2 combined images
Posted: 2018-03-12T10:06:47-07:00
by fmw42
I do not understand the question. Are you saying my command line does not work for you? If so, what is your Imagemagick version?
Re: Adding shadow to 2 combined images
Posted: 2018-03-12T10:11:12-07:00
by stealthrt
Yes I am saying that it does not work on my end.
The version I am using is: ImageMagick-7.0.7-26-Q16-x64-dll
Re: Adding shadow to 2 combined images
Posted: 2018-03-12T10:22:44-07:00
by fmw42
Change convert to magick.
Code: Select all
magick YnTf9.png \
\( -clone 0 -blur 0x10 -gravity center -crop 400x300+0+0 +repage \) \
\( -clone 0 -resize x300 \) \
\( -clone 1 -fill white -colorize 100 \) \
\( -clone 2 -fill black -colorize 100 \) \
\( -clone 3,4 -gravity center -compose over -composite -blur 0x15 -level 40x100% \) \
-delete 0,3,4 \
\( -clone 0,2 -gravity center -compose multiply -composite \) \
-delete 0,2 +swap \
-gravity center -compose over -composite \
result.png
That works fine for me on IM 7.0.7.25 Q16 Mac OSX.
Note the above is Unix syntax. For windows:
Code: Select all
magick YnTf9.png ^
( -clone 0 -blur 0x10 -gravity center -crop 400x300+0+0 +repage ) ^
( -clone 0 -resize x300 ) ^
( -clone 1 -fill white -colorize 100 ) ^
( -clone 2 -fill black -colorize 100 ) ^
( -clone 3,4 -gravity center -compose over -composite -blur 0x15 -level 40x100% ) ^
-delete 0,3,4 ^
( -clone 0,2 -gravity center -compose multiply -composite ) ^
-delete 0,2 +swap ^
-gravity center -compose over -composite ^
result.png
See
https://www.imagemagick.org/Usage/windows/
Re: Adding shadow to 2 combined images
Posted: 2018-03-13T00:14:28-07:00
by stealthrt
Still doesnt seem to be working for me
Re: Adding shadow to 2 combined images
Posted: 2018-03-13T09:36:58-07:00
by stealthrt
Any suggestions?
Re: Adding shadow to 2 combined images
Posted: 2018-03-13T10:53:30-07:00
by fmw42
I am not a Windows user, so do not know what might be wrong. But if you are running this is .bat file, then double the % to %%
Re: Adding shadow to 2 combined images
Posted: 2018-03-14T00:04:40-07:00
by stealthrt
Yep that was the issue. Not having the %% was the issue. Now having to convert it to C# :/