pThumb icon indicating copy to clipboard operation
pThumb copied to clipboard

Adding background color to transparent png and output format jpg

Open labr1005 opened this issue 8 years ago • 2 comments

Can you confirm that it's really not possible to add a background color to a transparent png and change the output format to jpg?

On the phpthumb demo page it works... http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php#x9

[[phpthumbof? &input=`transparent.png` &options=`bg=FF0000`]]

Result: red background, png. Close, but still a (large) png.

[[phpthumbof? &input=`transparent.png` &options=`bg=FF0000&f=jpg`]]

Result: black background, jpg.

[[phpthumbof? &input=`transparent.png` &options=`bg=FF0000` &useResizer=`0`]]

Result: cropped image (squared, ???), white background, png.

[[phpthumbof? &input=`transparent.png` &options=`bg=FF0000&f=jpg` &useResizer=`0`]]

Result: cropped image (squared, ???), white background, jpg.

labr1005 avatar Aug 30 '16 15:08 labr1005

Doing it in 2 steps seems to work, nesting or using toPlaceholder. But this just doesn't feel right...

[[phpthumbof? &input=`[[phpthumbof? &input=`transparent.png` &options=`bg=FF0000`]]` &options=`f=jpg`]]
[[phpthumbof? &input=`transparent.png` &options=`bg=FF0000` &toPlaceholder=`imageWithBg`]]
[[phpthumbof? &input=`[[+imageWithBg]]` &options=`f=jpg`]]

labr1005 avatar Aug 31 '16 16:08 labr1005

I tracked this one down to this line: https://github.com/modxcms/Resizer/blob/master/core/components/resizer/model/vendor/oo12/reductionist/src/Reductionist/Reductionist.php#L411

The check for !$outputIsJpg prevents the creation of a jpg with a background color.

But why?

labr1005 avatar Nov 19 '17 10:11 labr1005