Jump to content

Is there a function to reduce ppi to anything other than 75?


johnhenry

Recommended Posts

I am trying to use the GD library functions to reduce the size and ppi of images.  Unfortunately my server does not support imagick, which can do this,  but I have worked out a way to do the job, except that the process always makes the image 75 ppi.  I would rather have some control over the pixel density.

 

Can anyone suggest an answer please?

 

Here is my code......

 

<?php
$filename = 'my.jpg';
$size_multiple = .5;//change to suit dimensions wanted
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($filename);
$new_width = $width * $size_multiple;
$new_height = $height * $size_multiple;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, null, 100);
?> 

I think you mean dpi.

 

did you try and lower the quality?

 

<?php
$filename = 'my.jpg';
$size_multiple = .5;//change to suit dimensions wanted
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($filename);
$new_width = $width * $size_multiple;
$new_height = $height * $size_multiple;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, null, 70);//<-- the number change here
?> 

dpi is controlled in the image header information

 

there is a function made by someone to change the dpi if wanted to, but i would think it get fuzzy if go lower

default browser dpi is 72 and 96 I believe

 

http://www.php.net/manual/en/function.imagejpeg.php#83347

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.