Kod zmniejszania (funkcje resize i resize2):
<?php function resize($filef, $new_width, $new_height, $thumb, $quality) { if ($info === false) return false; $img = null; $img = imagecreatefromjpeg($filef); $th = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]); imagejpeg($th, $filef, $quality); imagedestroy($th); imagedestroy($img); return true; } function resize2($filef, $new_width, $new_height, $thumb, $quality) { if ($info === false) return false; $img = null; $img = imagecreatefromjpeg($filef); $th = imagecreatetruecolor(80, 80); imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]); imagejpeg($th, $filef, $quality); imagedestroy($th); imagedestroy($img); return true; } ?>
Kod wgrywania (funkcja uruchamiana kilkakrotnie w przypadku kilku plików):
function adpic($id,$arg,$position) { $path="../pliki/".$id; if ($info[0]>$info[1]) { if ($info[0]>625) { $height=(625/$info[0])*$info[1]; resize($path."/".$newimage, 625, $height, $path."/".$newimage, 75); } } elseif ($info[0]<$info[1]) { if ($info[1]>450) { $width=(450*$info[0])/$info[1]; resize($path."/".$newimage, $width, 450, $path."/".$newimage, 75); } } if ($info[0]<=$info[1]) { $thumb_height = (80/$info[0])*$info[1]; resize2($path."/thumb_".$newimage, 80, $thumb_height, $path."/thumb_".$newimage, 80); } elseif ($info[0]>$info[1]) { $thumb_width=(80*$info[0])/$info[1]; resize2($path."/thumb_".$newimage, $thumb_width, 80, $path."/thumb_".$newimage, 80); } }