mehr1362
سه شنبه 12 دی 1391, 15:56 عصر
سلام دوستان.
من يه مشكلي براي resize كردن عكس دارم.
يه تابعي دارم كث عكس و كوچيك ميكنه و ذخيره ميكنه.ولي من ميخوام به جاي ذخيره كردن،عكس كوچيك شده رو بهم نمايش بده.ولي به جاي عكس error cannot be displyed because it contains eroor ميده.
header('Content-type: image/jpeg');
function ResizeImage($picture,$max,$pre)
{
$dir="";
list($width,$height,$type)=getimagesize($dir.$pict ure);
if($width>$max || $height>$max)
{
if($type==1)
{
$func="imagecreatefromgif";
$func2="imagegif";
}
else if($type==2)
{
$func="imagecreatefromjpeg";
$func2="imagejpeg";
}
else if($type==3)
{
$func="imagecreatefrompng";
$func2="imagepng";
}
$src_img=$func($dir.$picture);
$oh = imagesy($src_img); # original height
$ow = imagesx($src_img); # original width
$new_h = $oh;
$new_w = $ow;
if($oh > $max || $ow > $max)
{
$r = $oh/$ow;
$new_h = ($oh > $ow) ? $max : $max*$r;
$new_w = $new_h/$r;
}
$dst_img = ImageCreateTrueColor($new_w,$new_h);
ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img),
ImageSY($src_img));
$func2($dst_img,$dir.$pre."$picture");
$newimag=$pre."$picture";
$oldpic=$picture;
if(file_exists($oldpic))
{
unlink($oldpic);
}
//return $newimag;
return imagejpeg($newimag);
}
}
echo ResizeImage($_GET['img'],'20','img_2');
اگر راهنماييم كنيد ممنون ميشم.
من يه مشكلي براي resize كردن عكس دارم.
يه تابعي دارم كث عكس و كوچيك ميكنه و ذخيره ميكنه.ولي من ميخوام به جاي ذخيره كردن،عكس كوچيك شده رو بهم نمايش بده.ولي به جاي عكس error cannot be displyed because it contains eroor ميده.
header('Content-type: image/jpeg');
function ResizeImage($picture,$max,$pre)
{
$dir="";
list($width,$height,$type)=getimagesize($dir.$pict ure);
if($width>$max || $height>$max)
{
if($type==1)
{
$func="imagecreatefromgif";
$func2="imagegif";
}
else if($type==2)
{
$func="imagecreatefromjpeg";
$func2="imagejpeg";
}
else if($type==3)
{
$func="imagecreatefrompng";
$func2="imagepng";
}
$src_img=$func($dir.$picture);
$oh = imagesy($src_img); # original height
$ow = imagesx($src_img); # original width
$new_h = $oh;
$new_w = $ow;
if($oh > $max || $ow > $max)
{
$r = $oh/$ow;
$new_h = ($oh > $ow) ? $max : $max*$r;
$new_w = $new_h/$r;
}
$dst_img = ImageCreateTrueColor($new_w,$new_h);
ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img),
ImageSY($src_img));
$func2($dst_img,$dir.$pre."$picture");
$newimag=$pre."$picture";
$oldpic=$picture;
if(file_exists($oldpic))
{
unlink($oldpic);
}
//return $newimag;
return imagejpeg($newimag);
}
}
echo ResizeImage($_GET['img'],'20','img_2');
اگر راهنماييم كنيد ممنون ميشم.