Folks !
When I use this simplest command to convert from PNG to JPEG I get a large black area in JPEG file.
convert 10.png 10.jpg
These images are available here:
http://www.metarmap.com/outgoing/10.png
http://www.metarmap.com/outgoing/10.jpg
PNG image is a tile generated using gdal2tile command with nodata value = 51, 51 51.
Tile rendering software handles PNG tiles fine but has large black area when using JPEG tiles.
Whats the correct command to convert above PNG to JPG so the white/transparent area in PNG file is cutout from image ie JPEG file has no black area at all ?
thanks,
-Sanjay
Converting PNG to JPEG - black background
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting PNG to JPEG - black background
JPEG does not support transparency. If your PNG images have any transparency, they will be removed and usually leaving black behind. You can change the color to anything you want.
convert image.png -background somecolor -flatten image.jpg
convert image.png -background somecolor -flatten image.jpg
Re: Converting PNG to JPEG - black background
Add a 1-pixel black frame to the JPG, then -trim to get rid of the black frame and black area.
Code: Select all
convert 10.jpg -bordercolor black -border 1x1 -trim 10-trimmed.jpg
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Converting PNG to JPEG - black background
You should use -alpha remove rather than mis-use -flatten.
It has the same effect, but the alpha on is faster and more memory efficient. It also works with "mogrify", where -flatten will not.
It has the same effect, but the alpha on is faster and more memory efficient. It also works with "mogrify", where -flatten will not.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Converting PNG to JPEG - black background
Why one pixel... you can add a zero pixel borderglennrp wrote:Add a 1-pixel black frame to the JPG, then -trim to get rid of the black frame and black area.Code: Select all
convert 10.jpg -bordercolor black -border 1x1 -trim 10-trimmed.jpg
Code: Select all
convert 10.png -bordercolor black -border 0 10.jpg
However as mentioned the best way is...
Code: Select all
convert 10.png -background black -alpha remove 10.jpg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/