Jump to content

[SOLVED] Image resize


joecooper

Recommended Posts

Hi.  i am using the following code to resize an image and display it to the user.

 

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

 

the problem with this is it looses quality when it resizes. round edges become a bit squared and you can notice defects. the original file is 1600x1200 and 1.8MB, then after it resizes to say 1024x768, the filesize is <300kb

 

is there any other code i could use that will resize with good quality

Link to comment
https://forums.phpfreaks.com/topic/167169-solved-image-resize/
Share on other sites

Hi Joe,

 

Try using imagecopyresampled (http://uk2.php.net/imagecopyresampled)

 

Something like:

 

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

Link to comment
https://forums.phpfreaks.com/topic/167169-solved-image-resize/#findComment-881432
Share on other sites

Try using imagecopyresampled (http://uk2.php.net/imagecopyresampled)

 

Something like:

 

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

 

... did you not just paste back to him EXACTLY what he put in his first post?

Link to comment
https://forums.phpfreaks.com/topic/167169-solved-image-resize/#findComment-881434
Share on other sites

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.