26. august 2003 - 17:00Der er
12 kommentarer og 1 løsning
Billede størelse
Er der en som har et script så hvis der er et bille som er breder end 640px Så vil den vise det som et 640px billede og så self X i højden? og hvis det er mindre end 640 i breden skal den ikke lave noget op på billedet?
//Thumb function Thumb($sourcefile, $targetfile) { $max_width = 640; $jpegqual = 100; /* Get the dimensions of the source picture */ $picsize=getimagesize("$sourcefile"); $source_x = $picsize[0]; $source_y = $picsize[1]; if ($source_x > $max_width) { $delta = $max_width/$source_x; } $dest_x = round($source_x*$delta); $dest_y = round($source_y*$delta); $source_id = imageCreateFromJPEG("$sourcefile"); /* Create a new image object (not neccessarily true colour) */
$target_id=imagecreatetruecolor($dest_x, $dest_y); /* resize the original picture and copy it into the just created image object. Because of the lack of space I had to wrap the parameters to several lines. I recommend putting them in one line in order keep your code clean and readable */
$target_pic=imagecopyresampled($target_id,$source_id, 0,0,0,0, $dest_x,$dest_y, $source_x,$source_y); /* Create a jpeg with the quality of "$jpegqual" out of the image object "$target_pic". This will be saved as $targetfile */
imagejpeg ($target_id,"$targetfile",$jpegqual); }//END Thumb
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.