List Info

Thread: note 78523 added to function.imagejpeg




note 78523 added to function.imagejpeg
user name
2007-10-16 04:50:25
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 -- h
ttp://www.php.net/manual/en/function.imagejpeg.php
Edit        -- https://master
.php.net/note/edit/78523
Del: integrated  -- h
ttps://master.php.net/note/delete/78523/integrated
Del: useless     -- http
s://master.php.net/note/delete/78523/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/78523/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78523
Reject      -- https://mast
er.php.net/note/reject/78523
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )