Convert PNG images to JPEG using GD library with SUBSAMPLING OFF

410 views Asked by At

I want to convert png images to jpeg on the fly, the only library which is installed on my system are the gd extensions.

I convert a png to jpeg successfully, even converting transparency as white color, the only problem is, that the resulting jpegs have subsampling.

Irfanview outputs following as image information: "JPEG, quality: 100, subsampling ON (2x2)". Also the dpi fields are not filled with any value.

The consumer of my jpegs has problems displaying them (it is closed software, nothing i can do here sadly)

Normal jpegs without subsampling and where the dpi fields have values work without problem.

So my question is, how to get rid of subsampling? thank you in advance!

Here is my code:

$image = imagecreatefrompng("file.png");
$bg = imagecreatetruecolor(imagesx($image), imagesy($image));
imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
imagealphablending($bg, TRUE);
imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
imagedestroy($image);
imagejpeg($bg);
1

There are 1 answers

0
likemusic On

Seems that it is still impossible according to https://github.com/libgd/libgd/issues/210