Tuesday, October 11, 2022

[FIXED] how to create 8bit jpeg in gd using php

Issue

I'm trying to figure out if it's possible to save a jpeg as an 8bit version instead of 16 bit or 24 bit.

I'm currently using imagecreate and then saving using imagejpeg but I can't see any parameters in the manual to allow for 8bit versions.

I've searched stackoverflow and php.net I find it hard to believe this isn't something easily achievable..

Thanks in advance


Solution

Have you tried imagemagic:

convert SRC.jpg -depth 8 -normalize  DEST.jpg

and with PHP:

<?php
error_reporting(E_ALL);
$SRC = 'src.jpg';
$DEST = 'dest.jpg';
$handle = popen("convert $SRC -depth 8 -normalize $DEST 2>&1", 'r');
$read = fread($handle, 2096);
pclose($handle);
?>


Answered By - nad2000
Answer Checked By - Robin (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.