put JPG on diff-size background without loss of information
Posted: 2014-01-10T13:11:08-07:00
Hi all,
I want to take a huge JPG and create a new, larger JPG consisting of the original JPG surrounded by a solid-color border. The new JPG should have the same IPTC metadata as the original (especially same colorspace). There should be no loss of quality for the original image in the center. Can it be done?
I've tried creating a solid-color background image, and then composing the original on top of it, but this loses my IPTC metadata, and the final image has a 5% lower byte size than the original (suggesting some loss of quality). Here's what I've tried:
K:\>identify rainbow.jpg
rainbow.jpg JPEG 3008x1960 3008x1960+0+0 8-bit sRGB 1.188MB 0.000u 0:00.001
K:\>convert -resize 4000x4000 xc:white back.jpg
K:\>composite -gravity center rainbow.jpg back.jpg out.jpg
K:\>identify out.jpg
out.jpg JPEG 4000x4000 4000x4000+0+0 8-bit sRGB 1.146MB 0.000u 0:00.000
NOTE: final 1.146MB smaller than original 1.188MB, despite massive larger px size
Is there some better technique to use here? I also tried "convert -resize 4000x4000! -fill white original.jpg out.jpg" but it stretches/distorts my source image, instead of just surrounding it with a border.
Our scenario is that our API sends photo JPGs to dozens of different print labs. Our convention has always been that if the image aspect ratio doesn't exactly match the print aspect ratio, the lab should crop-to-fit. We now have some images for which we want to shrink the image and fill with a background color, so that nothing is ever cropped if the image-size & print-size don't match. These are huge & expensive prints, so I want to avoid quality loss, and want to avoid losing any IPTC metadata which the print lab might require for doing the best-quality print.
I want to take a huge JPG and create a new, larger JPG consisting of the original JPG surrounded by a solid-color border. The new JPG should have the same IPTC metadata as the original (especially same colorspace). There should be no loss of quality for the original image in the center. Can it be done?
I've tried creating a solid-color background image, and then composing the original on top of it, but this loses my IPTC metadata, and the final image has a 5% lower byte size than the original (suggesting some loss of quality). Here's what I've tried:
K:\>identify rainbow.jpg
rainbow.jpg JPEG 3008x1960 3008x1960+0+0 8-bit sRGB 1.188MB 0.000u 0:00.001
K:\>convert -resize 4000x4000 xc:white back.jpg
K:\>composite -gravity center rainbow.jpg back.jpg out.jpg
K:\>identify out.jpg
out.jpg JPEG 4000x4000 4000x4000+0+0 8-bit sRGB 1.146MB 0.000u 0:00.000
NOTE: final 1.146MB smaller than original 1.188MB, despite massive larger px size
Is there some better technique to use here? I also tried "convert -resize 4000x4000! -fill white original.jpg out.jpg" but it stretches/distorts my source image, instead of just surrounding it with a border.
Our scenario is that our API sends photo JPGs to dozens of different print labs. Our convention has always been that if the image aspect ratio doesn't exactly match the print aspect ratio, the lab should crop-to-fit. We now have some images for which we want to shrink the image and fill with a background color, so that nothing is ever cropped if the image-size & print-size don't match. These are huge & expensive prints, so I want to avoid quality loss, and want to avoid losing any IPTC metadata which the print lab might require for doing the best-quality print.