PHP код:
<?php
/* hello from sch */
function resizing ($type_img,$source_src,$max_size_w,$max_size_h,$sufix = "_s.",$path,$prefix = "") {
$path_info = pathinfo($source_src);
$file_extension = $path_info["extension"];
$params = getimagesize($source_src);
switch ( $params[2] ) {
case 1: $source = imagecreatefromgif($source_src); break;
case 2: $source = imagecreatefromjpeg($source_src); break;
case 3: $source = imagecreatefrompng($source_src); break;
}
//$max_size_w = 710; $max_size_h = 550; // size for image
if ( $params[0] > $max_size_w || $params[1] >$max_size_h ) {
$koef_w = $max_size_w / $params[0]; // width
$koef_h = $max_size_h / $params[1]; // height
if ( $koef_w < $koef_h )
{ // width
$koef = $koef_w;
$koef_type="width";
}
else
{ // height
$koef = $koef_h;
$koef_type="height";
}
$resource_width = floor($params[0] * ($koef));
$resource_height = floor($params[1] * ($koef));
$resource = imagecreatetruecolor($max_size_w, $max_size_h);
if ($type_img == "small")
$back = imagecolorallocate($resource, 116, 116, 116); // grey small
else
$back = imagecolorallocate($resource, 255, 255, 255);
imagefill ( $resource, 0, 0, $back );
if ($koef_type == "height")
imagecopyresampled($resource, $source, ($max_size_w - $resource_width)/2, 0, 0, 0, $resource_width, $resource_height, $params[0], $params[1]);
else
imagecopyresampled($resource, $source, 0, ($max_size_h - $resource_height)/2, 0, 0, $resource_width, $resource_height, $params[0], $params[1]);
}
//else $resource = $source;
else {
$resource = imagecreatetruecolor($max_size_w, $max_size_h);
if ($type_img == "small")
$back = imagecolorallocate($resource, 116, 116, 116); //background for small pics
else
$back = imagecolorallocate($resource, 255, 255, 255); //background for big pics
imagefill ( $resource, 0, 0, $back );
imagecopyresampled($resource, $source, floor(($max_size_w - $params[0])/2), floor(($max_size_h - $params[1])/2), 0, 0, $params[0], $params[1], $params[0], $params[1]);
}
switch ( $params[2] ) {
case 1: imagegif($resource,$path."/".$prefix.$path_info['filename'].$sufix.$file_extension,100); break;
case 2: imagejpeg($resource,$path."/".$prefix.$path_info['filename'].$sufix.$file_extension,100); break;
case 3: imagepng($resource,$path."/".$prefix.$path_info['filename'].$sufix.$file_extension); break;
}
}
//============================================================================
//============================================================================
// Usage : resizing ( big/small , image_to_resize, max_width , max_height , suffix_to_filename , path , prefix_to_filename )
//============================================================================
if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
echo "ERROR";
exit(0);
}
$fileName = $_FILES["Filedata"]["name"];
$path = "path_for_images";
move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path."/".$fileName);
//-------------------------------------------------------------------------
$source_src = $path."/".$fileName;
resizing ('big',$source_src,710,550,"_s.",$path);
resizing ('small',$source_src,220,120,"_s.",$path,"preview_");
//------------------------------------------------------------------------------
//delete source file
unlink($source_src);
echo "OK";
?>
Может быть этот говнокод будет полезен. Изменяет размер картинки пропорционально. Будут вопросы - пишите, че-нить исправлю.
P.S. GrinGoO, ты вопрос читал, какая в жопу pathinfo? Человеку нужно изменить размер картинки.