A conversion of png with transparency, to jpg replaces the transparency with black instead of white. #104

Closed
cameronkendall opened this Issue Nov 25, 2012 · 10 comments

Comments

Projects
None yet
10 participants
@cameronkendall

I'm running a conversion using img.format('jpg'), but when the original image is .png with transparency, the transparency becomes black in the converted jpeg. It should be white.

manipulate! do |img|
img.resize "200x200"
img.background "rgba(255,255,255,0.0)"
img = yield(img) if block_given?
img.format('jpg')
img
end

@thiagofm

This comment has been minimized.

Show comment
Hide comment
@thiagofm

thiagofm Nov 25, 2012

Member

If you try to do it using imagemagick command line, what output does it give you? If possible, provide the imagemagick example you used.

Member

thiagofm commented Nov 25, 2012

If you try to do it using imagemagick command line, what output does it give you? If possible, provide the imagemagick example you used.

@cameronkendall

This comment has been minimized.

Show comment
Hide comment
@cameronkendall

cameronkendall Nov 26, 2012

Just tried these three commands in the console for an example png with transparency:

image = MiniMagick::Image.open("http://th02.deviantart.net/fs70/PRE/i/2012/160/b/d/cat_png_with_transparent_background_1_by_meinlilapark-d52tj0r.png")
image.background '#FFFFFF'
image.format('jpg')

Still getting a black background on the transparency for the output jpg file. I also tried image.background('rgba(255,255,255,0.0)')

I'm using mini_magick 3.4

Just tried these three commands in the console for an example png with transparency:

image = MiniMagick::Image.open("http://th02.deviantart.net/fs70/PRE/i/2012/160/b/d/cat_png_with_transparent_background_1_by_meinlilapark-d52tj0r.png")
image.background '#FFFFFF'
image.format('jpg')

Still getting a black background on the transparency for the output jpg file. I also tried image.background('rgba(255,255,255,0.0)')

I'm using mini_magick 3.4

@bensie

This comment has been minimized.

Show comment
Hide comment
@bensie

bensie Nov 29, 2012

Member

Keep in mind that MiniMagick is just a wrapper around ImageMagick's command line tools. You should probably refer to the IM docs and command line options (http://www.imagemagick.org/script/convert.php). If you can get a command working as you expect when calling convert from the command line, you can drop in the MiniMagick syntax and it will run the same command.

Member

bensie commented Nov 29, 2012

Keep in mind that MiniMagick is just a wrapper around ImageMagick's command line tools. You should probably refer to the IM docs and command line options (http://www.imagemagick.org/script/convert.php). If you can get a command working as you expect when calling convert from the command line, you can drop in the MiniMagick syntax and it will run the same command.

@bensie bensie closed this Nov 29, 2012

@fivedigit

This comment has been minimized.

Show comment
Hide comment
@fivedigit

fivedigit Apr 23, 2013

I've had this exact issue, but the problem is not in MiniMagick nor in ImageMagick. When saving the image to JPG, the alpha channel is just switched off, leaving you with a black background. You'll need to remove the alpha channel before changing the format, like so:

image = MiniMagick::Image.open("http://th02.deviantart.net/fs70/PRE/i/2012/160/b/d/cat_png_with_transparent_background_1_by_meinlilapark-d52tj0r.png")

image.combine_options do |c|
  c.background '#FFFFFF'
  c.alpha 'remove'
end
image.format 'jpg'

I've had this exact issue, but the problem is not in MiniMagick nor in ImageMagick. When saving the image to JPG, the alpha channel is just switched off, leaving you with a black background. You'll need to remove the alpha channel before changing the format, like so:

image = MiniMagick::Image.open("http://th02.deviantart.net/fs70/PRE/i/2012/160/b/d/cat_png_with_transparent_background_1_by_meinlilapark-d52tj0r.png")

image.combine_options do |c|
  c.background '#FFFFFF'
  c.alpha 'remove'
end
image.format 'jpg'
@luccasmaso

This comment has been minimized.

Show comment
Hide comment
@sprestel

This comment has been minimized.

Show comment
Hide comment
@ncri

This comment has been minimized.

Show comment
Hide comment
@ncri

ncri Sep 8, 2014

doesn't work for me

ncri commented Sep 8, 2014

doesn't work for me

@yosriady

This comment has been minimized.

Show comment
Hide comment
@yosriady

yosriady Nov 20, 2014

@fivedigit Woohoo! Thanks!

@fivedigit Woohoo! Thanks!

@chr1s1

This comment has been minimized.

Show comment
Hide comment

chr1s1 commented Apr 24, 2015

Thanks a lot! @fivedigit

@duecorda

This comment has been minimized.

Show comment
Hide comment

@funnel20 funnel20 referenced this issue in fastlane/fastlane Dec 4, 2017

Closed

[WIP] [frameit] Ensure both texts use same baseline #11096

4 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment