Genie1 05-09-2009, 08:55 PM Hello Team,
I would like a script which lets me upload one big picture, and after i click submit it creates three different size pics, which it saves automatically to my hard drive. Can some one please help me create this script, or give me a start code.
THank you for your time.
Have a good day
Genie1
sea4me 05-09-2009, 10:16 PM function createthumb($name,$filename,$new_w,$new_h){
if (file_exists($filename)) { unlink($filename); }
$system=explode('.',$name);
if (preg_match('/jpg|jpeg/',$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match('/png/',$system[1])){
$src_img=imagecreatefrompng($name);
}
if (preg_match('/gif/',$system[1])){
$src_img=imagecreatefromgif($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/jpg|jpeg/",$system[1])) {
imagejpeg($dst_img,$filename);
}
if (preg_match("/png/",$system[1])) {
imagepng($dst_img,$filename);
}
if (preg_match("/gif/",$system[1])) {
imagegif($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
chmod($filename,0644); // new file can sometimes have wrong permissions
}
Call it with:
createthumb(PATH TO FILE YOU WANT TO CREATE THUMB,PATH TO NEW FILE PLACE,NEW WIDTH,NEW HEIGHT);
timgolding 05-09-2009, 11:10 PM function createthumb($name,$filename,$new_w,$new_h){
if (file_exists($filename)) { unlink($filename); }
$system=explode('.',$name);
if (preg_match('/jpg|jpeg/',$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match('/png/',$system[1])){
$src_img=imagecreatefrompng($name);
}
if (preg_match('/gif/',$system[1])){
$src_img=imagecreatefromgif($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/jpg|jpeg/",$system[1])) {
imagejpeg($dst_img,$filename);
}
if (preg_match("/png/",$system[1])) {
imagepng($dst_img,$filename);
}
if (preg_match("/gif/",$system[1])) {
imagegif($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
chmod($filename,0644); // new file can sometimes have wrong permissions
}
Call it with:
createthumb(PATH TO FILE YOU WANT TO CREATE THUMB,PATH TO NEW FILE PLACE,NEW WIDTH,NEW HEIGHT);
Which requires GD installed on your server
|
|