Changeset 3531 for trunk/php/lib/thumbnail_lib.php
- Timestamp:
- 03/12/09 09:11:52 (9 months ago)
- Files:
-
- 1 modified
-
trunk/php/lib/thumbnail_lib.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/php/lib/thumbnail_lib.php
r3082 r3531 1 1 <?php 2 # Movable Type (r) Open Source (C) 2001-200 8Six Apart, Ltd.2 # Movable Type (r) Open Source (C) 2001-2009 Six Apart, Ltd. 3 3 # This program is distributed under the terms of the 4 4 # GNU General Public License, version 2. … … 29 29 # [2] thumbnail width for file name 30 30 # [3] thumbnail width for file name 31 function _calculate_size ($width, $height, $scale ) {31 function _calculate_size ($width, $height, $scale, $square) { 32 32 # Calculate thumbnail size 33 33 $thumb_w = $this->src_w; … … 41 41 $thumb_w_name = $thumb_w; 42 42 $thumb_h_name = $thumb_h; 43 } elseif ($square) { 44 if ($width > 0) { 45 $thumb_w = $width; 46 $thumb_h = $width; 47 $thumb_w_name = $width; 48 $thumb_h_name = $width; 49 } else { 50 $thumb_w = $height; 51 $thumb_h = $height; 52 $thumb_w_name = $height; 53 $thumb_h_name = $height; 54 } 43 55 } elseif ($width > 0 || $height > 0) { 44 56 $thumb_w_name = 'auto'; … … 94 106 95 107 # Load or generate a thumbnail. 96 function get_thumbnail (&$dest, &$width, &$height, $id, $scale = 0, $format = '%f-thumb-%wx%h-%i%x', $dest_type = 'auto' ) {108 function get_thumbnail (&$dest, &$width, &$height, $id, $scale = 0, $format = '%f-thumb-%wx%h-%i%x', $dest_type = 'auto', $square = false) { 97 109 if (empty($this->src_file)) return false; 98 110 if (!file_exists($this->src_file)) return false; … … 126 138 127 139 # Calculate thumbnail size 128 list ($thumb_w, $thumb_h, $thumb_w_name, $thumb_h_name) = $this->_calculate_size($width, $height, $scale );140 list ($thumb_w, $thumb_h, $thumb_w_name, $thumb_h_name) = $this->_calculate_size($width, $height, $scale, $square); 129 141 $width = $thumb_w; 130 142 $height = $thumb_h; … … 134 146 $dest = $this->_make_dest_name($thumb_w_name, $thumb_h_name, $format, $dest_type, $id); 135 147 } 136 137 148 # Generate 138 149 if(!file_exists($dest)) { … … 145 156 } 146 157 158 # if square modifier is enable, crop & resize 159 $src_x = 0; 160 $src_y = 0; 161 $target_w = $this->src_w; 162 $target_h = $this->src_h; 163 if ($square) { 164 if ($this->src_w > $this->src_h) { 165 $src_x = (int)($this->src_w - $this->src_h) / 2; 166 $src_y = 0; 167 $target_w = $this->src_h; 168 } else { 169 $src_x = 0; 170 $src_y = (int)($this->src_h - $this->src_w) / 2; 171 $target_h = $this->src_w; 172 } 173 } 174 147 175 # Create thumbnail 148 176 $dst_img = imagecreatetruecolor ( $thumb_w, $thumb_h ); 149 $result = imagecopyresampled ( $dst_img, $src_img, 0, 0, 0, 0,150 $thumb_w, $thumb_h, $t his->src_w, $this->src_h);177 $result = imagecopyresampled ( $dst_img, $src_img, 0, 0, $src_x, $src_y, 178 $thumb_w, $thumb_h, $target_w, $target_h); 151 179 152 180 $output = $this->src_type;
