note 78523 added to function.imagejpeg

From: Date: Tue, 16 Oct 2007 09:50:25 +0000
Subject: note 78523 added to function.imagejpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-131419@lists.php.net to get a copy of this message
I could not find any information on changing the DPI information on a JPG file using the GD lib. Since changing this does not resize or scale the actual image, it is only a header-setting. The following snipplet will save your $image to $file and set the DPI to 150. <?php imagejpeg($image, $file, 75); // Change DPI $dpi_x = 150; $dpi_y = 150; // Read the file $size = filesize($file); $image = file_get_contents($file); // Update DPI information in the JPG header $image[13] = chr(1); $image[14] = chr(floor($dpi_x/255)); $image[15] = chr( $dpi_x%255); $image[16] = chr(floor($dpi_y/255)); $image[17] = chr( $dpi_y%255); // Write the new JPG $f = fopen($file, 'w'); fwrite($f, $msg, $size); fclose($f); ?> P.s. not fully tested (yet) but it works for my images ... ---- Server IP: 213.249.64.162 Probable Submitter: 82.173.160.146 ---- Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php Edit -- https://master.php.net/note/edit/78523 Del: integrated -- https://master.php.net/note/delete/78523/integrated Del: useless -- https://master.php.net/note/delete/78523/useless Del: bad code -- https://master.php.net/note/delete/78523/bad+code Del: spam -- https://master.php.net/note/delete/78523/spam Del: non-english -- https://master.php.net/note/delete/78523/non-english Del: in docs -- https://master.php.net/note/delete/78523/in+docs Del: other reasons-- https://master.php.net/note/delete/78523 Reject -- https://master.php.net/note/reject/78523 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131419) next »