0

I'm using TPDF 6.2.12 and I'm searching a way to convert PNG images to JPEG before using them in the Image() function, which works quite well with PNGs but generates a large output file.

I have no clue how to use the _toJPEG() function and have not found any working example yet.

Could somebody help me with a working example/code-snippet, or a better solution, please?

Edit:

$pngname = $path.$imagelist[$i].'.png'; 
$jpegname = $path.$imagelist[$i].'.jpg'; 
$image = imagecreatefrompng($pngname); 
imagejpeg($image, $jpegname); 
$pdf->Image($jpegname, $image_x[$i], $image_y[$i], $image_w[$i],
$image_h[$i], 'JPEG', '', '', true, 150, '', false, false, 0, false,
false, false); 
imagedestroy($image); 
unlink($jpegname); 

This works perfectly fine but is rather clumsy: open png, write jpeg, open jpeg, delete jpeg

M.Ludwig
  • 1
  • 2
  • 1
    Have you tried this: http://stackoverflow.com/a/8951540/2672599 ? – jeoj Sep 17 '15 at 09:31
  • 1
    Or have you tried http://stackoverflow.com/questions/1201798/use-php-to-convert-png-to-jpg-with-compression – RiggsFolly Sep 17 '15 at 09:31
  • 1
    Or have you tried a simple Google for `php convert png to jpg` Over 3 million results, one must be helpful – RiggsFolly Sep 17 '15 at 09:32
  • The classical PHP approach is well known to me - I was just hoping for an "elegant" native TCPDF way using the existing classes. – M.Ludwig Sep 17 '15 at 09:41

0 Answers0