PDA

Просмотр полной версии : Маштабирование картинок


UnOuter
18.12.2005, 18:15
Хотелось бы получить иходник позволяющий маштабировать не только JPG но и GIF PNG И JPЕG изображения средставми PHP.
Вот Вариант позволяющий маштабировать только JPG

function fuckpic($upload, $mini_upload, $t_width, $t_height, $type){



function fuckpic($upload, $mini_upload, $t_width, $t_height, $type){

$img=ImageCreateFromJPEG($upload);
if ($img) {
$w = imagesx($img);
$h = imagesy($img);
$scale = min($t_width/$w, $t_height/$h);
if ($scale < 1) {
$new_width = floor($scale*$w);
$new_height = floor($scale*$h);
$img2 = imagecreatetruecolor($new_width, $new_height);
imagefill($img2, 0, 0, 0xFFFFFF);
imagecopyresampled($img2, $img, 0, 0, 0, 0,
$new_width, $new_height, $w, $h);
imagedestroy($img);
ImageJPEG($img2, $mini_upload, 90);
imagedestroy($img2);
}
}



}

Trotil
18.12.2005, 19:51
[QUOTE]UnOuter:
Кроме ImageCreateFromJPEG() и ImageJPEG() есть аналогичные функции и для других форматов:
resource imagecreatefromgif ( string filename ) (http://php.rinet.ru/manual/ru/function.imagecreatefromgif.php) и bool imagegif ( resource image [, string filename] ) (http://php.rinet.ru/manual/ru/function.imagegif.php);
resource imagecreatefrompng ( string filename ) (http://php.rinet.ru/manual/ru/function.imagecreatefrompng.php) и bool imagepng ( resource image [, string filename] ) (http://php.rinet.ru/manual/ru/function.imagepng.php);
resource imagecreatefromwbmp ( string filename ) (http://php.rinet.ru/manual/ru/function.imagecreatefromwbmp.php) и bool imagewbmp ( resource image [, string filename] ) (http://php.rinet.ru/manual/ru/function.imagewbmp.php).
Можно сделать три разные функции или свести все случаи в одну...