PDA

View Full Version : چجوری کاری کنم این تابع اپلود عکس کیفت عکسا رو هر چقدر که میخوام کم کنه



saeed-71
پنج شنبه 30 مرداد 1393, 13:55 عصر
سلام.
چجوری کاری کنم این تابع اپلود عکس کیفت عکسا رو هر چقدر که میخوام کم کنه



function SafeUpload($name, $max_size, $filesize) {
$root = str_replace('\\', '/', dirname(__FILE__));
$allowedTypes = array ('image/gif', 'image/jpeg', 'image/png', 'image/wbmp');
if(!isset($_FILES [$name])) {
return false;
}
$file = &$_FILES [$name];
if($file ['error'] == 0 && in_array($file ['type'], $allowedTypes) && $file ['size'] <= $max_size) {
$in = '';
switch($file ['type']) {
case 'image/gif':
$in = 'ImageCreateFromGIF';
break;
case 'image/jpeg':
$in = 'ImageCreateFromJPEG';
break;
case 'image/png':
$in = 'ImageCreateFromPNG';
break;
case 'image/wbmp':
$in = 'ImageCreateFromWBMP';
break;
}
if($in == '') {
return false;
}
$w=245;
$h=208;
$crop = false;
list($width, $height) = getimagesize($file['tmp_name']);
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*abs($r-$w/$h)));
} else {
$height = ceil($height-($height*abs($r-$w/$h)));
}
$newwidth = $w;
$newheight = $h;
} else {
if ($w/$h > $r) {
$newwidth = $h*$r;
$newheight = $h;
} else {
$newheight = $w/$r;
$newwidth = $w;
}
}
$src = $in($file ['tmp_name']);
$dst = imagecreatetruecolor($newwidth, $newheight);
$im = imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$stamp = imagecreatefrompng('');
$marge_right = 2;
$marge_bottom = 2;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopy($dst,$stamp,imagesx($dst) - $sx - $marge_right,imagesy($dst)-$sy-$marge_bottom,0,0,imagesx($stamp),imagesy($stamp)) ;

$time = time();
while(file_exists($root . '/../../upload/' . $time . '.jpg')) {
$time++;
}

//$quality = 100;

do {

ImageJPEG($dst, $root . '/../../upload/' . $time . '.jpg');

}
while(filesize($root . '/../../upload/' . $time . '.jpg') > $filesize && $quality > 0);
if(file_exists($root . '/../../upload/' . $time . '.jpg')){
ImageDestroy($dst);
ImageDestroy($src);
$ax = $time;
return $ax;
}

}// end function

arash691
جمعه 31 مرداد 1393, 01:07 صبح
سایز عکس رو کوچیک کن thumbnail ...


http://webcheatsheet.com/php/create_thumbnail_images.php