Page 1 of 1

image rotate black background transparent not working.

Posted: 2018-07-01T21:19:42-07:00
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

Re: image rotate black background transparent not working.

Posted: 2018-07-01T22:23:49-07:00
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.

Re: image rotate black background transparent not working.

Posted: 2018-07-05T17:59:06-07:00
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.

Re: image rotate black background transparent not working.

Posted: 2018-07-05T19:00:32-07:00
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

Re: image rotate black background transparent not working.

Posted: 2018-07-05T19:30:39-07:00
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

Re: image rotate black background transparent not working.

Posted: 2018-07-05T21:33:20-07:00
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

Re: image rotate black background transparent not working.

Posted: 2018-07-06T09:34:01-07:00
by GeeMack
brizey02 wrote:
2018-07-05T19:30:39-07:00
This 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.