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);
}
}
}
Вот Вариант позволяющий маштабировать только 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);
}
}
}