I would like to add drop shadows to thumbnails. It appears that MagickShadowImage may be at least part of a solution.
After much headscratching, I went to the source code and managed to figure out that the first two arguments are expected in the interval [0...100] and are the desired mean (Gaussian distribution) and standard deviation of the percentage of transparency. (Be nice if the doc said that. )
In Microsoft Image Composer, I am used to setting transparency and hardness/softness using a sliding scale. The standard deviation of transparency would seem to be equivalent to the softness slider. The x and y arguments would seem to represent the ditance of the point light source that creates the shadow. But not the angle?
Starting with a wand containing an image 175 x 131 pixels, my program calls:
MagickShadowImage(wand,10,10,5,5)
The returned image is 215 x 171 pixels. OK. Sounds reasonable. Unfortunately, when displayed on a white background, this image was totally blank. Upon further investigation I found the following image statistics:
Max Min Mean
R 255 255 255
G 255 255 255
B 255 255 255
A 255 239.4 230
Aha! The shadow image is totally white, with opacity from 90 to 100%, with a mean of 93.9%. MIC has a color argument.
So, my question now is, how do I get a shadow with black pixels, or perhaps, navy?
Am I correct in deducing that what I do now is place this shadow image over a solid color opaque image of the same size, then place the original over the top left corner of that and flatten them?
And get a different light source angle by rotating the shadow?
I may get the hang of this yet!
MagickShadowImage
I had never really paid any attention to the mathematics behind drop shadows, so am still getting up to speed. With the aid of Google I now realize that virtually all imaging software uses Gaussian blur to generate drop shadows.
From Anthony, I read about the IM alpha channel:
"after IM v6.3.0, to bring IM in line with SVG standards and other graphics packages, this value was inverted so as to represent an 'alpha' transparency value. In otherwords 'FF' now represented fully-opauqe and '00' is fully transparent."
http://www.cit.gu.edu.au/~anthony/graph ... els/#color
Since I am using 6.3.1, I assume an alpha value of 255 is fully opaque, 0 is fully transparent.
Your suggested parameters of 80,3,5,5 yields:
Min alpha 51 (20% of 255, or 20% opacity)
mean alpha ~79 (31%)
std alpha ~59 (23%)
Experimenting with various values for the first argument (call it p1), I found that the minimum alpha (expressed as a percentage) was always 100-p1. Since the minimum alpha is the minimum opacity of the pixels, I would say that p1 represents the maximum transparency, hence I view it as a "transparency" parameter.
Getting a handle on how the parameters affect the mean and standard deviation of alpha is more elusive. I will need to run a set of calibrated tests I guess, and plot a function thru the results.
From Anthony, I read about the IM alpha channel:
"after IM v6.3.0, to bring IM in line with SVG standards and other graphics packages, this value was inverted so as to represent an 'alpha' transparency value. In otherwords 'FF' now represented fully-opauqe and '00' is fully transparent."
http://www.cit.gu.edu.au/~anthony/graph ... els/#color
Since I am using 6.3.1, I assume an alpha value of 255 is fully opaque, 0 is fully transparent.
Your suggested parameters of 80,3,5,5 yields:
Min alpha 51 (20% of 255, or 20% opacity)
mean alpha ~79 (31%)
std alpha ~59 (23%)
Experimenting with various values for the first argument (call it p1), I found that the minimum alpha (expressed as a percentage) was always 100-p1. Since the minimum alpha is the minimum opacity of the pixels, I would say that p1 represents the maximum transparency, hence I view it as a "transparency" parameter.
Getting a handle on how the parameters affect the mean and standard deviation of alpha is more elusive. I will need to run a set of calibrated tests I guess, and plot a function thru the results.
Following this command line technique:
http://www.cit.gu.edu.au/~anthony/graph ... tml#shadow
I came up with the following MagickWand API sequence that works great. However, I was wondering if there was a different technique using the MagickWand API that involves fewer operations, uses less time, et., etc.:
http://www.cit.gu.edu.au/~anthony/graph ... tml#shadow
I came up with the following MagickWand API sequence that works great. However, I was wondering if there was a different technique using the MagickWand API that involves fewer operations, uses less time, et., etc.:
Code: Select all
/* nailwand MagickWand contains a JPG thumbnail */
/* blackwand PixelWand contains color black */
/* whitewand PixelWand contains color white */
nailclone = CloneMagickWand(nailwand)
MagickSetImageBackgroundColor(nailclone,blackwand)
MagickShadowImage(nailclone,80,3,5,5)
MagickAddImage(nailclone,nailwand)
DestroyMagickWand(nailwand)
MagickSetImageBackgroundColor(nailclone,whitewand)
nailwand = MagickMosaicImages(nailclone)
DestroyMagickWand(nailclone)
/* nailwand now contains a shadowed JPG thumbnail on a white backround */