Ok, I asked this question in another thread but I didn't get it to work.. I have a code that upload and renames a image. Now I want that image to be resized to 700*525 pixels, and overwrite the big uploaded image with the small resized image. I have tested some examples i found but can't get it to work.. this is the code I have to upload and rename the image, can someone plz show me how and where to put in the resize code..//thnx <?php //create the directory if doesn't exists (should have write permissons) if(!is_dir("./files")) mkdir("./files", 0755); //move the uploaded file move_uploaded_file($_FILES['Filedata']['tmp_name'], "MY_IMG.jpg"); //move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']); //chmod("./files/MY_IMG.jpg", 0777); ?>
I'm not familiar with PHP so I can't help you there, but wouldn't it be easier to just manually resize the image in your photo editor.
No beacuse the image is uploaded to a server and then loaded into a flash movie, so it has to be resized when uploaded
Dont kmow how much this might help but here is some code that resizes an image. I just can tell you exactly waht part of the code does the image resizing: $img=$_GET['img']; if (!Is_Dir(DIR_CACHE)) { mkdir(DIR_CACHE, 0777); } // IMAGE RESIZE AND SAVE TO FIT IN $new_width x $new_height if ($img!='' && file_exists($img)) { $w=$_GET['w']; $h=$_GET['h']; $thumb=strtolower(preg_replace('/\W/is', "_", "$img $w $h")); $changed=0; if (file_exists($img) && file_exists(DIR_CACHE.$thumb)) { $mtime1=filemtime(DIR_CACHE.$thumb); $mtime2=filemtime($img); if ($mtime2>$mtime1) $changed=1; } elseif (!file_exists(DIR_CACHE.$thumb)) { $changed=1; } if ($changed) { $filename=$img; $new_width=(int)@$w; $new_height=(int)@$h; $lst=GetImageSize($filename); $image_width=$lst[0]; $image_height=$lst[1]; $image_format=$lst[2]; if ($image_format==1) { Header("Content-Type:image/gif"); readfile($filename); exit; } elseif ($image_format==2) { $old_image=imagecreatefromjpeg($filename); } elseif ($image_format==3) { $old_image=imagecreatefrompng($filename); } else { exit; } if (($new_width!=0) && ($new_width<$image_width)) { $image_height=(int)($image_height*($new_width/$image_width)); $image_width=$new_width; // $image_height=$new_height; } if (($new_height!=0) && ($new_height<$image_height)) { $image_width=(int)($image_width*($new_height/$image_height)); $image_height=$new_height; // $image_width=$new_width; } // $new_image=imageCreate($image_width, $image_height); // for old GDlib $new_image=imageCreateTrueColor($image_width, $image_height); $white = ImageColorAllocate($new_image, 255, 255, 255); ImageFill($new_image, 0, 0, $white); // imagecopyresampled // imageCopyResized (for old GDlib) imageCopyResampled( $new_image, $old_image, 0, 0, 0, 0, $image_width, $image_height, imageSX($old_image), imageSY($old_image)); imageJpeg($new_image, DIR_CACHE.$thumb); } Header("Content-type:image/jpeg"); readfile(DIR_CACHE.$thumb); exit; } // ---------------------------------------------------------------------- $init_dir="./"; if (IsSet($HTTP_GET_VARS['dir'])) { $dir=$HTTP_GET_VARS['dir']; $dir=preg_replace("/\.+/", ".", $dir); } if (IsSet($dir) && ($dir!=$init_dir)) { $directory=$dir; $tmp=array_reverse(explode('/', $dir)); array_shift($tmp); array_shift($tmp); $out['UP']=urlencode(implode('/', array_reverse($tmp))."/"); } else { $directory=$init_dir; } $dir=opendir($directory); $k=0; $on_row=IMAGES_ROW; if (file_exists($directory."files.txt")) { $data=LoadFile($directory."files.txt"); $lines=explode("\n", $data); for($i=0;$i<count($lines);$i++) { $ar=explode(' ', trim($lines[$i])); $tmp=array_shift($ar); $descriptions[$tmp]=implode(' ', $ar); } } while ($file=readdir($dir)) { if (Is_Dir($directory."/$file") && ($file!='tmp') && ($file!='.') && ($file!='..')) { $directories[]=array('FILENAME'=>$file, 'DIR'=>$directory, 'DESCRIPTION'=>$descriptions[$file], 'URL'=>urlencode($directory."$file/")); } if (!Is_file($directory."/$file")) continue; $ext=strtolower(substr($file, -3)); if ($ext!='gif' && $ext!='jpg') continue; $rec=array(); $rec["FILENAME"]=$file; $size=(int)(filesize($directory."/".$file)/1024); if ($size>1024) { $rec["SIZE"]=(((int)($size*100/1024))/100)." Mb"; } else { $rec["SIZE"]=$size." Kb"; } if (IsSet($descriptions[$file])) { $rec['DESCRIPTION']=$descriptions[$file]; } $rec["DIR"]=$directory; if (($k+1)%$on_row==0) { $rec['NEXT_ROW']=1; } $k++; $files[]=$rec; } include('./template.php'); // ---------------------------------------------------------------------- function LoadFile($filename) { // loading file $f=fopen("$filename", "r"); $data=""; if ($f) { $data=fread($f, filesize($filename)); fclose($f); } return $data; } ?> Code (markup):
hehe ok.. a little to much to handle for me.. I cant really tell what's what.. just need the code strip that is needed for my code and where to put it.. thanks anyway..
If you use some resizing script you will need to enable it on server.. on 80% resizing sripts are working
To resize use the following function: resizepic("sourceimage.jpg","resizedpic.jpg",200,200); PHP: You can alter that width & height as you want function resizepic($name,$filename,$new_w,$new_h){ $system=explode('.',$name); if (preg_match('/jpg|jpeg/',$system[1])){ $src_img=imagecreatefromjpeg($name); } if (preg_match('/png/',$system[1])){ $src_img=imagecreatefrompng($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("/png/",$system[1])) { imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } PHP:
Dear i m making a picture galery script.what i want more is that when i browse pictures for uploading from PC, it is a big resolution file, i want an automatically thumbnail generate and saved to another folder.Beacuse at main page i need thumbnails, which r linked to big pictures.i know it is done with gd, but don't know how to do it. any one can help
thanx tamilsoft! I just found a problem, when image in 4:3 with resolution bigger than 1200*960 is uploaded the code wont resize it..? It works perfect on images that for ex. have resolution 640*480.. Is that something I can adjust in the code..? //thanks
There is a offer to get pictures put onto canvas A2.. My image is 148KB they say they need at least 1MB to transform my image onto canvas.. I don't have a clue, does anyone on here know how to do this, in simple terms please
You'll need a better resolution / quality image. It's not possible to up the quality of the image - you can make it bigger (in filesize) but it won't make the quality of the file any better. For an A2 image, for print, you'll need an image of 300 dpi or better (most images saved for the web are 120dpi or less) - which will mean you'll need an image that is 4961 x 7016 (or vice versa) to have it printed in 300 dpi. That's an image of 34.8 megapixels. Or an image of minimum 2-3 MB (as a jpg). http://web.forret.com/tools/megapixel.asp?width=7016&height=4961 <- look there for how many MB different types of image-quality / file types demands. The point is - that 148kB image is not even fit for printing on A4 paper, and you'll need a lot better quality for full-color print. Note: this does NOT apply if what you want to print is line-art (vector) - if that's the case, then you can get away with a lot smaller file-sizes, but it'll still need to be a raw vector-file.
Thank you popicle, it was some art I had seen, doesn't look like i will be hanging it on my wall, never mind, thanks anyway !