სურათის გადაზომვა GD2-ის საშუალებით

სურათის გადაზომვა და ახალი სურათის მიღება

[cc lang=”php”]function imageResize($filename, $path, $newfilename, $newpath, $newwidth, $newheight) {
$image_type = end(explode(“.”, strtolower($filename)));
switch($image_type) {
case ‘jpg’:
$source = imagecreatefromjpeg($path.$filename);
break;
case ‘png’:
$source = imagecreatefrompng($path.$filename);
break;
case ‘gif’:
$source = imagecreatefromgif($path.$filename);
break;
default:
echo(“Error Invalid Image Type”);
die;
break;
}
$file = $newfilename . $filename;
$fullpath = $newpath . $file;
list($width, $height) = getimagesize($path.$filename);
if ($width>$height) {
$newheight = $height / ($width/$newwidth);
}
elseif ($height>$width) {
$newwidth = $width / ($height/$newheight);
}

$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $fullpath, 60);
$filepath = $fullpath;
return $filepath;

}
[/cc]

და შემდგომ ვიძახებთ ამ ფუნქციას –

[cc lang=”php”]imageResize(‘image.jpg’, ‘files’, ‘trm_’, ‘trm/’, ‘200’, ‘200’);[/cc]

ფუნქცია უზრუნველყოფს სურათის გადაზომვას პროპორციულად. ამის გაკონტროლება ხდება
ფუნქციის ამ ნაწილით

[cc lang=”php”]list($width, $height) = getimagesize($path.$filename);
if ($width>$height) {
$newheight = $height / ($width/$newwidth);
}
elseif ($height>$width) {
$newwidth = $width / ($height/$newheight);
}[/cc]

წარმატებები

Leave a Reply

Your email address will not be published. Required fields are marked *