{% else-1 %}
Создание превьюшек *

                        
<?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;
}
# - > Пример работы: < - #

echo '<img src="mini_'.resize('http://www.webnotes.com.ua/demo/img-resize/test.jpg',200).'" />';
?>
3 36 0
Без комментариев...