Page 1 of 1

Scaling and Converting a .png to .jpg

Posted: 2016-01-19T06:10:48-07:00
by SoulBeaver
Hello everyone!

Lest my question seem too innocuous, this is the workflow I'm trying to achieve:

Image

I take a .png with a transparent background, fill the background with a new color, resize the image and convert it to a .jpg. This gives me the following command in IM:
convert -resize 800x1200 -background #000000 -alpha Background -quality 100% src.png dest.jpg
The result is this:

Image

I've tried stripping away everything and perform a simple resize and conversion in two steps:
convert -resize 800x1200 src.png src_tmp.png
convert -quality 100% src_tmp.png dest.jpg
But that still results in:

Image

Source image here: Image

Further Notes:

1. I have tried several filters including triangle, Lancsoz, LancsozSharp and a few others
2. I've tried changing the colorspace: convert -colorspace RGB -resize 800x1200 -colorspace sRGB src.png dest.jpg

Re: Scaling and Converting a .png to .jpg

Posted: 2016-01-19T06:30:06-07:00
by snibgo
"-alpha Background" changes fully-transparent pixels to black, which is only part of the work you want. You should also use the correct syntax (read the input, do the processing, write the output). So we have:

Code: Select all

convert dehEQJ3.png -resize 800x1200 -background black -flatten out.jpg

Re: Scaling and Converting a .png to .jpg

Posted: 2016-01-19T07:07:33-07:00
by GeeMack
SoulBeaver wrote:I take a .png with a transparent background, fill the background with a new color, resize the image and convert it to a .jpg. This gives me the following command in IM:
convert -resize 800x1200 -background #000000 -alpha Background -quality 100% src.png dest.jpg
Using IM 6.9.3-1 Q16 x64 on Windows 7 64, I get the result from your first example by cloning the image, making the clone all black, compositing the image over the black, then resizing it to 800x1200 after it's on the black background, something like this...

Code: Select all

convert dehEQJ3.png ( +clone -flatten -fill black -colorize 100 ) +swap -composite -resize 800x1200 -quality 100 dest.jpg
It looks like you have to flatten that clone in order to get the entire rectangle black, otherwise the "-colorize" only makes the oval center black.

EDITED TO ADD: Looks like snibgo gave you the simpler method while I was writing my reply! :)