Change transparent color and -page not work.

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
DannyGM

Change transparent color and -page not work.

Post by DannyGM »

Hello

I have two questions

1:
I trying to change the trasnparent color (without -fill).

Code: Select all

convert -size 100X100 xc:none -alpha off -transparent-color blue -fill yellow -draw "circle 50,50 20,20" -blur 5X10 win:
This what i get:
Image

Why the background color it's black? I want it to be blue!

------------------------------
2:
I am trying to compose two images and set the offset of the second image.

Code: Select all

convert -size 100X100 xc:red -size 50X50 -page +20+20 xc:blue -composite win:
Image
Why the second image (xc:red) always sit on the upper left corner?

Sorry about my grammar, English isn'y my tang.

Thank you.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Change transparent color and -page not work.

Post by el_supremo »

Try this:

Code: Select all

convert -size 100X100 xc:red -size 50X50  xc:blue -geometry +20+20 -composite win:
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Change transparent color and -page not work.

Post by magick »

Try this command:
  • convert -size 100X100 xc:red -size 50X50 xc:blue -geometry +20+20 -composite win:
The geometry option sets the offset when compositing.
DannyGM

Re: Change transparent color and -page not work.

Post by DannyGM »

Thank you for your fast answer.

Now it's work.

What about changing the transparent color of object?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Change transparent color and -page not work.

Post by anthony »

I trying to change the trasnparent color (without -fill).

Code: Select all

convert -size 100X100 xc:none -alpha off -transparent-color blue -fill yellow -draw "circle 50,50 20,20" -blur 5X10 win:
This what i get:
Image

Why the background color it's black? I want it to be blue!
It is black as you used a canvas color of 'none' then turned off the transparency channel on the very next option! 'none' is defined as fully-transparency-black. so the result of that was a starting canvas of just black.

-transparent-color for NOT change the image at all. it just sets the color that is to be used for the transparent color index in the GIF color table. It basically defined the normally undefined color for older applications that ignore the GIF transparency features, of the file format.

That is it does NOTHING for you.
I am trying to compose two images and set the offset of the second image.

Code: Select all

convert -size 100X100 xc:red -size 50X50 -page +20+20 xc:blue -composite win:
Image
Why the second image (xc:red) always sit on the upper left corner?
The second image is blue, so I assume you ment xc:blue.

the problem you have is the usage difference between a -page (or virtual canvas offset) and -geometry (or alpha composition offset)
What is used depends on what type of operation you are applying,

-page is used for sequences of images to align those images relative to each other. That is image Layering, and Animations. It is not -gravity effected.

-geometry is -gravity effected so you can center or placing images relative to to say the bottom or right edges. It is used specifically for alpha composition (which usually ignores -page offsets)

See IM Examples... Alpha Composition
Composite Geometry/Gravity Settings
vs Layer Canvas/Page Offsets
http://www.imagemagick.org/Usage//compose/#geometry

Lots of links here to both layer and alpha composition methods.
though more general use of both can be found in the 'Layering Images" area of IM Examples
http://www.imagemagick.org/Usage/layers/

Note that one operator actually uses BOTH simultaneously.
-layers composite which merges two separate sequences of images with relative -page offsets together, using a global -geometry offset (relative to the virtual canvas size) to position the two sequences.

See IM examples
Animation/Layer Composition
http://www.imagemagick.org/Usage/anim_mods/#composite
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
DannyGM

Thank you Anthony

Post by DannyGM »

Thank you Anthony.

Here is my code, for changing the transparenr color

Code: Select all

convert  logo: ( -size 500X500 xc:blue -transparent blue -fill yellow
-draw "circle 200,200 50,50" -blur 5X10 )  -gravity west  -composite  -resize 200X200 candelete.jpg
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Thank you Anthony

Post by anthony »

DannyGM wrote:Thank you Anthony.

Here is my code, for changing the transparenr color

Code: Select all

convert  logo: ( -size 500X500 xc:blue -transparent blue -fill yellow
-draw "circle 200,200 50,50" -blur 5X10 )  -gravity west  -composite  -resize 200X200 candelete.jpg
Ok you create a canvas, make it blue, then make the blue transparent, draw a yellow circle and blur it (without using -channel RGBA)

The result would in all likely hood NOT have a transparent blue. Mathematically transparent colors are undefined, and as a result generally get reset to transparent black. so that canvas will probably NOT be quite what you expect, and is likely to vary a lot from IM version to IM version.

I repeat full-transparency color is undefined, and how operators handle it is also undefined.

See the examples in blur with transparency
http://www.imagemagick.org/Usage/convolve/#blur_channel

What exactly are you wanting???? a yellow circle bluring out to a bluish semi-transparency and then full-transparency?

The best way to gurantee this is to handle the color and alpha channel separatally.

\( -size 500X500 xc:blue -fill yellow -draw "circle 200,200 50,50" \
\( xc:black -fill white -draw "circle 200,200 50,50" \) \
-blur 0x20 +matte -compose CopyOpacity -composite \)

NOTE the extra internal parenthesis for the second draw!

Now that will have a yellow circle with a blue semi-transparency.
Guranteed, and does not relay on any semi-transparent color remaining something it isn't.

In fact it will produce a higher quality result as the draw will create an anti-aliased yellow-blue color border even BEFORE the blur adds to the effect!

A simplier way is to just blue a blue border with a properly handled transparency blur (ignore transparent colors correctly)

-size 500x500 -xc:none -fill yellow -stroke blue -strokewidth 10 \
-draw "circle 200,200 50,50" -channel RGBA -blur 0x10

probably a LOT simplier to generate too!


Transparency is tricky. and relying on transparency to have a specific color is a BAD idea... period.

WARNING: as yellow is a complement of blue in RGB space the transparency shading may not be what you expect, as yellow will shade to black, in the red and green channel, while blue shades from black to semi-transparent blue to full-transparency.

As a result you will probably get a yellow - darkgray - blue - transparent gradient.

you can see this using a yellow-blue gradient image

convert -size 50x400 gradient:yellow-blue show:

Note the dark gray in the middle caused by RGB color space
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply