I need a solution to automatically change the DPI of uploaded photos from 300 to 72. I've coded this bit of script to read the 14th through 18th bit of binary data of a JPEG and update the DPI. The script below seems to be writing to the jpeg, but the afterwards, the jpeg is unreadable and when I rerun the script, it still shows the image DPI hasn't changed. Anyone have experience changing DPI of an image?
[code=php]
<?php
$filename = 'familyshot33.j pg';
// open file for writing
$f = fopen($filename , 'r+');
$string = fread($f,20);
// show dpi before
echo hexdec(bin2hex( substr($string, 14, 2))) . ' ' . hexdec(bin2hex( substr($string, 16, 2))) .'<br/>';
// update dpi
$image = substr_replace( $string, pack("Cnn", 0x01, 72, 72), 13, 5);
// show dpi after
echo hexdec(bin2hex( substr($image, 14, 2))) . ' ' . hexdec(bin2hex( substr($image, 16, 2))) .'<br/>';
// write and close
fwrite($f, $image, filesize($filen ame));
fclose($f);
?>
[/code]
[code=php]
<?php
$filename = 'familyshot33.j pg';
// open file for writing
$f = fopen($filename , 'r+');
$string = fread($f,20);
// show dpi before
echo hexdec(bin2hex( substr($string, 14, 2))) . ' ' . hexdec(bin2hex( substr($string, 16, 2))) .'<br/>';
// update dpi
$image = substr_replace( $string, pack("Cnn", 0x01, 72, 72), 13, 5);
// show dpi after
echo hexdec(bin2hex( substr($image, 14, 2))) . ' ' . hexdec(bin2hex( substr($image, 16, 2))) .'<br/>';
// write and close
fwrite($f, $image, filesize($filen ame));
fclose($f);
?>
[/code]
Comment