Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.