PHP GD 2x ресайз


<?php
$filename = ""; // путь до картинки
$filename_logo = ""; // путь до логотипа PNG
$small_size = 100; // максимальный размер превьюшки

$info_img = getimagesize($filename); // собераем информацию изображения
list($width, $height) = $info_img;

// определяем пропорции
if($width > $height) {
$s_width = $small_size;
$s_height = $small_size*($height/$width);
}
if($width < $height) {
$s_width = $small_size*($width/$height);
$s_height = $small_size;
}
if($width == $height) {
$s_width = $small_size;
$s_height = $small_size;
}

$small_image = imagecreatetruecolor($s_width, $s_height);
$big_image = imagecreatetruecolor($width, $height);


// определяем тип изображения
if($info_img['mime'] == 'image/gif') {
$image = imagecreatefromgif($filename);
}
if($info_img['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($filename);
}
if($info_img['mime'] == 'image/png') {
$image = imagecreatefrompng($filename);
}

imagecopyresampled($small_image, $image, 0, 0, 0, 0, $s_width, $s_height, $width, $height);
imagecopyresampled($big_image, $image, 0, 0, 0, 0, $width, $height, $width, $height);

// накладываем лого на большое изображение
imagealphablending($image, true);
$logo_image = imagecreatefrompng($filename_logo);
$logo_width = ImageSX($logo_image);
$logo_height = ImageSY($logo_image);
imagecopy($big_image, $logo_image, $width-($logo_width+10), $height-($logo_height+10), 0, 0, $logo_width, $logo_height);

// сохраняем 2 изображения
imagejpeg($small_image, "picture/small_picture.jpg", 80);
imagejpeg($big_image, "picture/big_picture.jpg", 80);
?>
Скачать файл txt fb2