<?php function resize ($filename, $size) { $pref = 'mini_'; $img = strtolower(strrchr(basename($filename), ".")); $imgname = basename($filename); $formats = array('.jpg', '.gif', '.png', '.bmp'); if (in_array($img, $formats)) { list($width, $height) = getimagesize($filename); $new_height = $height * $size; $new_width = $new_height / $width; $thumb = imagecreatetruecolor($size, $new_width); switch ($img) { case '.jpg': $source = @imagecreatefromjpeg($filename); break; //создаем превьюшки case '.gif': $source = @imagecreatefromgif($filename); break; case '.png': $source = @imagecreatefrompng($filename); break; case '.bmp': $source = @imagecreatefromwbmp($filename); break; } imagecopyresized($thumb, $source, 0, 0, 0, 0, $size, $new_width, $width, $height); switch ($img) { case '.jpg': imagejpeg($thumb, $pref.$imgname); break; case '.gif': imagegif($thumb, $pref.$imgname); break; case '.png': imagepng($thumb, $pref.$imgname); break; case '.bmp': imagewbmp($thumb, $pref.$imgname); break; } } else return 'Error'; @imagedestroy($thumb); @imagedestroy($source); return $imgname; } ?>