4 * Copyright (C) 2010, Free Software Foundation, Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Ian Denhardt <ian@zenhack.net>
25 * @copyright 2010 Free Software Foundation, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
30 function photo_make_thumbnail($filename)
35 $size_src = getimagesize(INSTALLDIR . '/file/' . $filename);
36 $image_type = $size_src[2];
40 $image_src = imagecreatefromjpeg(INSTALLDIR . '/file/' . $filename);
43 $image_src = imagecreatefrompng(INSTALLDIR . '/file/' . $filename);
46 $image_src = imagecreatefromgif(INSTALLDIR . '/file/' . $filename);
52 $width_src = $size_src[0];
53 $height_src = $size_src[1];
55 $ratio_src = (float) $width_src / (float) $height_src;
56 $ratio_dest = (float) $width_dest / (float) $height_dest;
58 if ($ratio_src > $ratio_dest) {
59 $height_crop = $height_src;
60 $width_crop = (int)($height_crop * $ratio_dest);
61 $x_crop = ($width_src - $width_crop) / 2;
63 $width_crop = $width_src;
64 $height_crop = (int)($width_crop / $ratio_dest);
68 $image_dest = imagecreatetruecolor($width_dest, $height_dest);
70 imagecopyresampled($image_dest, $image_src, 0, 0, $x_crop, 0, $width_dest, $height_dest, $width_crop, $height_crop);
71 switch ($image_type) {
73 imagejpeg($image_dest, INSTALLDIR . '/file/' . 'thumb.' . $filename, 100);
76 imagepng($image_dest, INSTALLDIR . '/file/thumb.' . $filename);
79 imagegif($image_dest, INSTALLDIR . '/file/thumb.' . $filename);
83 imagedestroy($image_src);
84 imagedestroy($image_dest);