note 93705 added to function.imagecreate

From: Date: Wed, 23 Sep 2009 17:29:31 +0000
Subject: note 93705 added to function.imagecreate
Groups: php.notes 
Request: Send a blank email to php-notes+get-160989@lists.php.net to get a copy of this message
if you want to create an image with a specific DPI, you can't control this directly from GD. If you have access to gd.h (rarely on a shared hosting) you can modify GD_RESOLUTION and give it your desired value. The solution that I found was directly manipulating the jpeg header bytes. I hope this sample code would helps someone because it took me 5 hours of digging to figure out i have no other options. <?php header('Content-Disposition: attachment; filename="myimg.jpg"'); header('Cache-Control: private'); $dst = imagecreatetruecolor(300, 300); /*this creates a 300x300 pixels image*/ ob_start(); /*don't send the output to the browser since we'll need to manipulate it*/ ImageJpeg($dst); $img = ob_get_contents(); ob_end_clean(); //byte #14 in jpeg sets the resolution type: 0=none, 1=pixels per inch, 2=pixels per cm //bytes 15-16 sets X resolution //bytes 17-18 sets Y resolution $img = substr_replace($img, pack('cnn',1,300,300),13,5); echo $img; ?> ---- Server IP: 209.41.74.194 Probable Submitter: 89.138.180.78 ---- Manual Page -- http://www.php.net/manual/en/function.imagecreate.php Edit -- https://master.php.net/note/edit/93705 Del: integrated -- https://master.php.net/note/delete/93705/integrated Del: useless -- https://master.php.net/note/delete/93705/useless Del: bad code -- https://master.php.net/note/delete/93705/bad+code Del: spam -- https://master.php.net/note/delete/93705/spam Del: non-english -- https://master.php.net/note/delete/93705/non-english Del: in docs -- https://master.php.net/note/delete/93705/in+docs Del: other reasons-- https://master.php.net/note/delete/93705 Reject -- https://master.php.net/note/reject/93705 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160989) next »