שלום שלום.
קודם כל, כל מה שאתה חושב שקיים אפשרי
הקטנת תמונה נעשת באמצעות GD.
GD הינה ספריה שאחראית על תמונות ב-PHP.
כתבתי פעם פונקציה שמקטינה תמוננה לגודל הרצוי ושומרת אותה.
תוכל להשתמש בה, אני לא בטוח שהיא הכי יעילה כי זה היה דיי מזמן, אבל גם תוכל ללמוד ממנה.
קישור ל-GD:
www.php.net/gd
הפונקציה שלי:
PHP קוד:
function ImageResize($src,$width,$height,$output) {
$info = explode(".",$src);
$ext = strtolower($info[1]);
if($ext == "jpeg" || $ext == "jpg") {
$source_image = imagecreatefromjpeg($src);
} elseif($ext == "gif") {
$source_image = imagecreatefromgif($src);
} else {
die("Unknown image file type. (know only jpeg,jpg,gif) Filename supplied: $src");
}
$filesize = (list($awidth,$aheight) = getimagesize($src));
$output_image = imagecreatetruecolor ($width, $height);
imagecopyresampled ($output_image, $source_image, 0,0,0,0, $width, $height, $awidth, $aheight);
if($ext == "jpeg" || $ext == "jpg") {
imagejpeg ($output_image,$output,100);
} else if ($ext == "gif") {
imagegif($output_image,$output,100);
}
imagedestroy ($source_image);
imagedestroy ($output_image);
}
כמו כן, הפונקציה תמוכת ב-GIF וב-JPEG,JPEG בלבד.
כמובן שניתן להוסיף PNG ללא שום בעיה, אם אתה רוצה תוסיף.
בהצלחה.
טל.