<?php// Inkluderer array der også $fotototalt er definertinclude("fotoarray.php");for($i = 0; $i < $fotototalt; $i++){ $bilde = $fotoimages[$i]; // Sjekker om den resizede filen allerde eksisterer if(file_exists('foto/'.$bilde.'.jpg')){ } // Hvis den resizede filen ikke eksisterer else{ // Sjekke om filen det skal skrives fra eksisterer, hvis den gjør det, utfør funksjonene if(file_exists('upload/foto/'.$bilde.'.jpg')){ fotoresizeToBigFile($bilde); fotoresizeToSmallFile($bilde); } }}/* ---------------- Når trykket på ---------------- */function fotoresizeToBigFile ($bilde){$sourcefile = './upload/foto/'.$bilde.'.jpg';$targetfile = './foto/'.$bilde.'.jpg';$dest_x = 1024;$dest_y = 680;$jpegqual = 80; /* Get the dimensions of the source picture */ $picsize=getimagesize($sourcefile); $source_x = $picsize[0]; $source_y = $picsize[1]; $source_id = imageCreateFromJPEG($sourcefile); if($source_x < $source_y){ $dest_x = 398; $dest_y = 600; } /* 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); return true;}/* --------- THUMBNAIL --------- */function fotoresizeToSmallFile ($bilde){$sourcefile = './upload/foto/'.$bilde.'.jpg';$targetfile = './foto/'.$bilde.'_t.jpg';$dest_x = 250;$dest_y = 166;$jpegqual = 80; /* Get the dimensions of the source picture */ $picsize=getimagesize($sourcefile); $source_x = $picsize[0]; $source_y = $picsize[1]; $source_id = imageCreateFromJPEG($sourcefile); if($source_x < $source_y){ //Definerer den nyresizede filen som sourcefile for å få et bedre utsnitt $sourcefile = "./foto/".$bilde.".jpg"; $picsize=getimagesize($sourcefile); $source_x = $picsize[0]; $source_y = $picsize[1]; $source_id = imageCreateFromJPEG($sourcefile); $cpy_x = ($source_x / 2) - ($dest_x / 2); $cpy_y = ($source_y / 2) - ($dest_y / 2); $new_img = imagecreatetruecolor($dest_x, $dest_y) or die("En ukjent feil oppstod"); imagecopyresampled($new_img, $source_id, 0, 0, $cpy_x, $cpy_y, $dest_x, $dest_y, $dest_x, $dest_y); imagejpeg ($new_img,$targetfile,$jpegqual); } else{ /* 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); return true; }}?>