resize images with good quality with gd2
Posted: Mon Jun 04, 2007 7:57 am
Hi Im resizing images with gd2 but the quality that I'm optaining is not what Im after, I will like to resize an image but respecting its quality(I will like the image not to pixel).
I dont know if this possible with gd2 this my code maybe I'm doing something wrong.
If someone could give the code a glance it would be nice.
Does anyone knows a better way???
I dont know if this possible with gd2 this my code maybe I'm doing something wrong.
Code: Select all
<?php
include ("includes/config.php");
include ("includes/funciones.php");
set_time_limit(0);
if ($_FILES['Filedata']['name']) {
//$nuevoNombre = time().".jpg";
$size = 300; // the thumbnail height
$filedir = 'galeria/'; // the directory for the original image
$thumbdir = 'galeria/'; // the directory for the thumbnail image
$prefix = 'big_';
$prefix1 = 'small_'; // the prefix to be added to the original name
$maxfile = '2000000';
$mode = '0666';
$userfile_name = $_FILES['Filedata']['name'];
$userfile_tmp = $_FILES['Filedata']['tmp_name'];
$userfile_size = $_FILES['Filedata']['size'];
$userfile_type = $_FILES['Filedata']['type'];
if (isset($_FILES['Filedata']['name']))
{
$prod_img = $filedir.$userfile_name;
$nuevoNombre = time();
$sufijo=".jpg";
$prod_img_thumb1 = $thumbdir.$prefix1.$nuevoNombre.$sufijo;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$new_width1 = 151;
$new_height1 = 132;
$destimg1=imagecreatetruecolor($new_width1,$new_height1)
or die('Problem In Creating image');
$srcimg1=imagecreatefromjpeg($prod_img)
or die('Problem In opening Source Image');
if(function_exists('imagecopyresampled'))
{
imagecopyresampled($destimg1,$srcimg1,0,0,0,0,$new_width1,$new_height1,ImageSX($srcimg1),ImageSY($srcimg1))
or die('Problem In resizing');
}else{
imagecopyresized($destimg1,$srcimg1,0,0,0,0,$new_width1,$new_height1,ImageSX($srcimg1),ImageSY($srcimg1))
or die('Problem In resizing');
}
imagejpeg($destimg1,$prod_img_thumb1,90)
//imagejpeg($destimg,$prod_img_thumb,90)
//imagejpeg($destimg,"hola",90);
or die('Problem In saving');
imagedestroy($destimg1);
}
@unlink($prod_img);
}
?>Does anyone knows a better way???