saeed-71
دوشنبه 06 مرداد 1393, 12:16 عصر
سلام.
این کد اپلود تصویرم خیلی خیلی کیفت عکسو میره پایین واتر مارکم خیلی بی کیفیت میکنه
نمیشه کاری کرد کیفیت تصاویر رو خودم تعیین کنم؟
واتر مارکم میخوام با کفیت 100% روش بزنه
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=450;
$h=338;
$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('../../img/logo.png');
$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
}// end isset
این کد اپلود تصویرم خیلی خیلی کیفت عکسو میره پایین واتر مارکم خیلی بی کیفیت میکنه
نمیشه کاری کرد کیفیت تصاویر رو خودم تعیین کنم؟
واتر مارکم میخوام با کفیت 100% روش بزنه
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=450;
$h=338;
$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('../../img/logo.png');
$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
}// end isset