Hi, am acest snippet care creeaza thumbnail-uri dupa imaginile uploadate dar nu e potrivit pt mine deoarece eu vrea sa creeze thumbnail-uri cu width si height fix, iar el creeaza in functie de height si nu reusesc sa il modific exact cum trebuie.Deci am nevoie ca thumb-urile sa fie de 80 pe 80, utilizand-ul asa cum e acum heightul e bun dar witdh-ul nu si imaginile sunt "distorsionate" din cauza formulei dupa care lucreaza el acum.
Snippet
CODE
if(isset($_POST['Submit'])){
$size = 80; // dimensiunea thumbnail-ului
$filedir = 'pics/'; // directorul imaginii pe care o vei uploada
$thumbdir = 'pics/'; // directorul imaginii thumbnail
$prefix = 'small_'; // prefixul adaugat imaginii
$maxfile = '2000000';
$mode = '0666';
$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];
if (isset($_FILES['image']['name'])){
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[1] <= $size)
{
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_height = $size;
$new_width = abs($new_height/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing');
ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
imagedestroy($destimg);
$size = 80; // dimensiunea thumbnail-ului
$filedir = 'pics/'; // directorul imaginii pe care o vei uploada
$thumbdir = 'pics/'; // directorul imaginii thumbnail
$prefix = 'small_'; // prefixul adaugat imaginii
$maxfile = '2000000';
$mode = '0666';
$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];
if (isset($_FILES['image']['name'])){
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[1] <= $size)
{
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_height = $size;
$new_width = abs($new_height/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing');
ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
imagedestroy($destimg);
Deci cine ma jauta sa il modific astfel incat sa creeze thumb-uri cu inaltime si latime prestabilita .
Multumesc anticipat