image rotate black background transparent not working.

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
brizey02
Posts: 4
Joined: 2017-05-19T06:16:12-07:00
Authentication code: 1151

image rotate black background transparent not working.

Post by brizey02 »

Cant seem to get transparency to work when using the command
convert $1s.jpg \( +clone -background black -rotate $2 \) -gravity center -compose Src -composite $1f.png
Tried -background none, transparent
Ubuntu Version: ImageMagick 6.8.9-9 Q16 x86_64 2018-06-11
Last edited by brizey02 on 2018-07-01T22:26:39-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: image rotate black background transparent not working.

Post by fmw42 »

JPG does not support transparency. So your input has no transparency. -compose src will not add transparency. You probably want to use -compose copy_opacity. See http://www.imagemagick.org/Usage/compose/#copyopacity

Always provide your Imagemagick version and platform when asking questions, since syntax may vary.
brizey02
Posts: 4
Joined: 2017-05-19T06:16:12-07:00
Authentication code: 1151

Re: image rotate black background transparent not working.

Post by brizey02 »

Code: Select all

convert test.png \( +clone -background 'rgba(0,0,0,0)' -rotate 75 \) -gravity center  -compose copy_opacity -composite debug.png
Does not work.
Also

Code: Select all

 convert test.jpg \( +clone -background 'rgba(0,0,0,0)' -rotate 75 \) -gravity center -compose Src copy_opacity -composite debug.png
 
Yelds transparency but does not rotate the image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: image rotate black background transparent not working.

Post by fmw42 »

-background does not change the background, it is just a setting that needs an operator to work. Cloning the image does not change it to grayscale. You need to make the clone into a grayscale or binary image and then rotate both, assuming you want the alpha channel to be rotated the same as the image. Perhaps you should provide your input image by posting to some free service and put the URL here and then explain how you want the transparency to look.

I am not sure what you want for transparency, but try

Code: Select all

convert test.png \( +clone -colorspace gray \) -background 'rgba(0,0,0,0)' -rotate 75 -gravity center  -compose copy_opacity -composite debug.png
or

Code: Select all

convert test.png \( +clone -colorspace gray -threshold 50% \) -background 'rgba(0,0,0,0)' -rotate 75 -gravity center  -compose copy_opacity -composite debug.png
Also your first post started with JPG. You are now starting with a PNG. Does the PNG have transparency already? If so, then just do

Code: Select all

convert test.png -background none -rotate 75 debug.png
brizey02
Posts: 4
Joined: 2017-05-19T06:16:12-07:00
Authentication code: 1151

Re: image rotate black background transparent not working.

Post by brizey02 »

This works great but the image is resized need to matain the same size

Code: Select all

convert test.png \( +clone -colorspace gray \) -background 'rgba(0,0,0,0)' -rotate 75 -gravity center  -compose copy_opacity -composite debug.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: image rotate black background transparent not working.

Post by fmw42 »

When you rotate an image, the bounding box gets bigger. Imagemagick does not automatically make it the same size as the original. You will need to resize it to the same original size.

Code: Select all

dim=$(convert test.png -format "%wx%h" info:)
convert test.png \( +clone -colorspace gray \) -background none -rotate 75 -gravity center  -compose copy_opacity -composite -resize $dim debug.png
If you were using IM 7, you could do it all in one command line.

If you do not want the resize and just want the image cropped, you can do

Code: Select all

dim=$(convert test.png -format "%wx%h" info:)
convert test.png \( +clone -colorspace gray \) -background none -rotate 75 -gravity center  -compose copy_opacity -composite -extent $dim debug.png
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: image rotate black background transparent not working.

Post by GeeMack »

brizey02 wrote: 2018-07-05T19:30:39-07:00This works great but the image is resized need to matain the same size
Maybe you'd do better to use "-distort" instead of "-rotate". Try something like this...

Code: Select all

convert input.jpg -set alpha -background none -virtual-pixel none -distort SRT 75 output.png
That keeps the same dimensions as the input image, and the triangular areas left over after the rotate should be transparent.
Post Reply