Jump to content

Image resize - no loss of dpi


AndieB

Recommended Posts

Hi all!

 

I have used the below script to resize images, but every picture uploaded seems to loss quality and I can not figure out why?

Perhaps anyone who reads this can help me out!

 

	// CHECK WHAT FORMAT THE PICTURE IS, LANDSCAPE OR PORTRAIT
$fileSize = getimagesize($uploaddir . $tmpnewfilename);
$new_file_width = $fileSize['width'];
$new_file_height = $fileSize['height'];

if ($new_file_height > $new_file_width) {
	$new_file_new_width = 427;
	$new_file_new_height = 307;

	$destimg = ImageCreateTrueColor( $new_file_new_width, $new_file_new_height ) or die( "Problem In Creating image" );
	$srcimg = ImageCreateFromJPEG( $uploaddir.$tmpnewfilename ) or die( "Problem In opening Source Image" );

	ImageCopyResampled( $destimg, $srcimg, 0, 0, 0, 0, $new_file_new_width, $new_file_new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing");
	ImageJPEG($destimg,$uploaddir.$newfilename) or die("Problem In saving");
	unlink($uploaddir . $tmpnewfilename);
} else {
	$new_file_new_width = 640;
	$new_file_new_height = 427;

	$destimg=ImageCreateTrueColor($new_file_new_width,$new_file_new_height) or die("Problem In Creating image");
	$srcimg=ImageCreateFromJPEG($uploaddir.$tmpnewfilename) or die("Problem In opening Source Image");

	ImageCopyResampled($destimg,$srcimg,0,0,0,0,$new_file_new_width,$new_file_new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing");
	ImageJPEG($destimg,$uploaddir.$newfilename) or die("Problem In saving");
	unlink($uploaddir . $tmpnewfilename);
}

 

Does the DPI (Dots Per Inch) change in the script above?

 

I would very much appreciate help!

 

Sincerely,

Andreas

Link to comment
Share on other sites

That's what images do - you are taking the same data and trying to place it all in a smaller (or larger) visual space.  this means that some interpolation will occur between pixels to try and replicate the colours.

 

The GD Library is not as sophisticated as graphic apps such as photoshop - they have sophistcaed algorithms and can far better utilise vector based algorithms to maintain the 'quality' of an image.

Link to comment
Share on other sites

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.