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
https://forums.phpfreaks.com/topic/54554-image-resize-no-loss-of-dpi/
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.

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.