Spread and image with opacity

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
excel
Posts: 18
Joined: 2015-12-19T13:16:12-07:00
Authentication code: 1151

Spread and image with opacity

Post by excel »

There is image.png with opacity.


Image

How to use -virtual-pixel white -spread and get this spread_image.png with opacity?

Image

The sample (spread_image.png) is not very nice, I tried to do it in Photoshop


Is it possible to do a similar actions with -raise (+raise) ?
Last edited by excel on 2015-12-22T08:37:23-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Spread and image with opacity

Post by Bonzo »

Not quite sure what you are after but there may be an example of what you want here: http://www.imagemagick.org/Usage/thumbnails/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Spread and image with opacity

Post by fmw42 »

try this (unix syntax)

Code: Select all

convert image.png \
\( -clone 0 -virtual-pixel white -spread 15 -blur 0x0.5 \) \
\( -clone 0 -alpha extract -virtual-pixel black -morphology erode diamond:15 -negate \) \
\( -clone 0-2 -compose over -composite \) \
-delete 1,2 \
\( -clone 0 -alpha extract \) \
-delete 0 \
 -alpha off -compose copy_opacity -composite result.png 
excel
Posts: 18
Joined: 2015-12-19T13:16:12-07:00
Authentication code: 1151

Re: Spread and image with opacity

Post by excel »

fmw42 wrote:try this (unix syntax)

Code: Select all

convert image.png \
\( -clone 0 -virtual-pixel white -spread 15 -blur 0x0.5 \) \
\( -clone 0 -alpha extract -virtual-pixel black -morphology erode diamond:15 -negate \) \
\( -clone 0-2 -compose over -composite \) \
-delete 1,2 \
\( -clone 0 -alpha extract \) \
-delete 0 \
 -alpha off -compose copy_opacity -composite result.png 


Hello, fmw42!
I placed a blue background to see white pixels

Your result has not white pixels at the bottom of inclined lines:


Image


It's my variant but need to lay the white pixels in the inclined lines

Code: Select all

convert -size 300x226 xc:none -background transparent -virtual-pixel white -spread 15 +write mpr:spread1 \
	\( image.png mpr:spread1 -composite +write result.png \)
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Spread and image with opacity

Post by fmw42 »

try this:

Code: Select all

convert image.png \
\( -clone 0 -alpha off -virtual-pixel white -spread 15 -blur 0x0.5 \) \
\( -clone 0 -alpha extract -virtual-pixel black -morphology erode diamond:15 -negate \) \
\( -clone 0-2 -compose over -composite \) \
-delete 1,2 \
\( -clone 0 -alpha extract \) \
-delete 0 \
 -alpha off -compose copy_opacity -composite result.png 
You can leave out the -blur if you don't want the spread softened.


This should be slightly more efficient:

Code: Select all

convert image.png -write mpr:img \
\( mpr:img -alpha off -virtual-pixel white -spread 15 \) \
\( mpr:img -alpha extract -virtual-pixel black -morphology erode diamond:15 \) \
-swap 0,1 -compose over -composite \
\( mpr:img -alpha extract \) \
 -alpha off -compose copy_opacity -composite result.png
excel
Posts: 18
Joined: 2015-12-19T13:16:12-07:00
Authentication code: 1151

Re: Spread and image with opacity

Post by excel »

fmw42 wrote:try this:

Code: Select all

convert image.png -write mpr:img \
\( mpr:img -alpha off -virtual-pixel white -spread 15 \) \
\( mpr:img -alpha extract -virtual-pixel black -morphology erode diamond:15 \) \
-swap 0,1 -compose over -composite \
\( mpr:img -alpha extract \) \
 -alpha off -compose copy_opacity -composite result.png


I have a question.
Why this image has some black pixels?
On the top of image and on the grass.

Image


Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Spread and image with opacity

Post by fmw42 »

The top is from the spread from her hair
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Spread and image with opacity

Post by fmw42 »

The two different input images you have provide have different colors in the transparent area. The first one was white and this one is black.

Look at:

Code: Select all

convert image.png -alpha off tmp1.png
convert black_pix.png -alpha off tmp2.png
This will replace the black in the second image with white and make the bottom spread white. Note that -virtual-pixel white only affects the area near the real border of the image (not where the image is transparent).

Code: Select all

 convert black_pix.png -background white -alpha background -write mpr:img \
\( mpr:img -alpha off -alpha off -virtual-pixel white -spread 15 \) \
\( mpr:img -alpha extract -virtual-pixel black -morphology erode diamond:15 \) \
-swap 0,1 -compose over -composite \
\( mpr:img -alpha extract \) \
 -alpha off -compose copy_opacity -composite result2.png
It does not change the top, since the black is her hair.
excel
Posts: 18
Joined: 2015-12-19T13:16:12-07:00
Authentication code: 1151

Re: Spread and image with opacity

Post by excel »

fmw42 wrote:The two different input images you have provide have different colors in the transparent area. The first one was white and this one is black.

It does not change the top, since the black is her hair.

Can we do it in a few steps for a perfect white pixels?
May be several exec-commands?

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Spread and image with opacity

Post by fmw42 »

try this

Code: Select all

convert black_pix.png -write mpr:img \
\( mpr:img -alpha off -fill white -colorize 100% -alpha on -write mpr:img2 \) \
+swap \
\( mpr:img2 -virtual-pixel none -spread 15 \) \
-compose over -composite result.png
excel
Posts: 18
Joined: 2015-12-19T13:16:12-07:00
Authentication code: 1151

Re: Spread and image with opacity

Post by excel »

fmw42 wrote:try this

Code: Select all

convert black_pix.png -write mpr:img \
\( mpr:img -alpha off -fill white -colorize 100% -alpha on -write mpr:img2 \) \
+swap \
\( mpr:img2 -virtual-pixel none -spread 15 \) \
-compose over -composite result.png

It's OK! Thank You!
Post Reply