Changeset 8912 for trunk/wp-admin/includes/image.php
- Timestamp:
- 09/17/2008 12:40:10 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/image.php
r8879 r8912 4 4 * 5 5 * @package WordPress 6 */ 7 8 /** 9 * wp_create_thumbnail() - Create a thumbnail from an Image given a maximum side size. 10 * 11 * @package WordPress 12 * @param mixed $file Filename of the original image, Or attachment id 13 * @param int $max_side Maximum length of a single side for the thumbnail 14 * @return string Thumbnail path on success, Error string on failure 15 * 16 * This function can handle most image file formats which PHP supports. 17 * If PHP does not have the functionality to save in a file of the same format, the thumbnail will be created as a jpeg. 6 * @subpackage Administration 7 */ 8 9 /** 10 * Create a thumbnail from an Image given a maximum side size. 11 * 12 * This function can handle most image file formats which PHP supports. If PHP 13 * does not have the functionality to save in a file of the same format, the 14 * thumbnail will be created as a jpeg. 15 * 16 * @since unknown 17 * 18 * @param mixed $file Filename of the original image, Or attachment id. 19 * @param int $max_side Maximum length of a single side for the thumbnail. 20 * @return string Thumbnail path on success, Error string on failure. 18 21 */ 19 22 function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) { 20 21 23 $thumbpath = image_resize( $file, $max_side, $max_side ); 22 24 return apply_filters( 'wp_create_thumbnail', $thumbpath ); … … 24 26 25 27 /** 26 * wp_crop_image() - Crop an Image to a given size. 27 * 28 * @package WordPress 28 * Crop an Image to a given size. 29 * 29 30 * @internal Missing Long Description 30 * @param int $src_file The source file 31 * @param int $src_x The start x position to crop from 32 * @param int $src_y The start y position to crop from 33 * @param int $src_w The width to crop 34 * @param int $src_h The height to crop 35 * @param int $dst_w The destination width 36 * @param int $dst_h The destination height 37 * @param int $src_abs If the source crop points are absolute 38 * @param int $dst_file The destination file to write to 39 * @return string New filepath on success, String error message on failure 40 * 31 * 32 * @since unknown 33 * 34 * @param string|int $src_file The source file or Attachment ID 35 * @param int $src_x The start x position to crop from. 36 * @param int $src_y The start y position to crop from. 37 * @param int $src_w The width to crop. 38 * @param int $src_h The height to crop. 39 * @param int $dst_w The destination width. 40 * @param int $dst_h The destination height. 41 * @param int $src_abs Optional. If the source crop points are absolute. 42 * @param string $dst_file Optional. The destination file to write to. 43 * @return string New filepath on success, String error message on failure. 41 44 */ 42 45 function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { … … 75 78 76 79 /** 77 * wp_generate_attachment_metadata() - Generate post Image attachment Metadata 78 * 79 * @package WordPress 80 * Generate post Image attachment Metadata. 81 * 80 82 * @internal Missing Long Description 81 * @param int $attachment_id Attachment Id to process 82 * @param string $file Filepath of the Attached image 83 * @return mixed Metadata for attachment 84 * 83 * 84 * @since unknown 85 * 86 * @param int $attachment_id Attachment Id to process 87 * @param string $file Filepath of the Attached image 88 * @return mixed Metadata for attachment 85 89 */ 86 90 function wp_generate_attachment_metadata( $attachment_id, $file ) { … … 121 125 122 126 } 127 123 128 return apply_filters( 'wp_generate_attachment_metadata', $metadata ); 124 129 } 125 130 126 131 /** 127 * wp_load_image() - Load an image which PHP Supports. 128 * 129 * @package WordPress 132 * Load an image which PHP Supports. 133 * 130 134 * @internal Missing Long Description 131 * @param string $file Filename of the image to load 132 * @return resource The resulting image resource on success, Error string on failure. 133 * 135 * 136 * @since unknown 137 * 138 * @param string $file Filename of the image to load. 139 * @return resource The resulting image resource on success, Error string on failure. 134 140 */ 135 141 function wp_load_image( $file ) { … … 154 160 155 161 /** 156 * get_udims() - Calculated the new dimentions for downsampled images 157 * 158 * @package WordPress 159 * @internal Missing Description 162 * Calculated the new dimentions for downsampled images. 163 * 164 * @since unknown 160 165 * @see wp_shrink_dimensions() 161 * @param int $width Current width of the image 162 * @param int $height Current height of the image 163 * @return mixed Array(height,width) of shrunk dimensions. 166 * 167 * @param int $width Current width of the image 168 * @param int $height Current height of the image 169 * @return mixed Array(height,width) of shrunk dimensions. 164 170 * 165 171 */ … … 167 173 return wp_shrink_dimensions( $width, $height ); 168 174 } 169 /** 170 * wp_shrink_dimensions() - Calculates the new dimentions for a downsampled image. 171 * 172 * @package WordPress 173 * @internal Missing Long Description 174 * @param int $width Current width of the image 175 * @param int $height Current height of the image 176 * @param int $wmax Maximum wanted width 177 * @param int $hmax Maximum wanted height 178 * @return mixed Array(height,width) of shrunk dimensions. 175 176 /** 177 * Calculates the new dimentions for a downsampled image. 178 * 179 * @since unknown 180 * @see wp_constrain_dimensions() 181 * 182 * @param int $width Current width of the image 183 * @param int $height Current height of the image 184 * @param int $wmax Maximum wanted width 185 * @param int $hmax Maximum wanted height 186 * @return mixed Array(height,width) of shrunk dimensions. 179 187 * 180 188 */ … … 183 191 } 184 192 185 // convert a fraction string to a decimal 193 /** 194 * Convert a fraction string to a decimal. 195 * 196 * @since unknown 197 * 198 * @param string $str 199 * @return int|float 200 */ 186 201 function wp_exif_frac2dec($str) { 187 202 @list( $n, $d ) = explode( '/', $str ); … … 191 206 } 192 207 193 // convert the exif date format to a unix timestamp 208 /** 209 * Convert the exif date format to a unix timestamp. 210 * 211 * @since unknown 212 * 213 * @param string $str 214 * @return int 215 */ 194 216 function wp_exif_date2ts($str) { 195 // seriously, who formats a date like 'YYYY:MM:DD hh:mm:ss'?196 217 @list( $date, $time ) = explode( ' ', trim($str) ); 197 218 @list( $y, $m, $d ) = explode( ':', $date ); … … 200 221 } 201 222 202 // get extended image metadata, exif or iptc as available 223 /** 224 * Get extended image metadata, exif or iptc as available 225 * 226 * @since unknown 227 * 228 * @param string $file 229 * @return bool|array False on failure. Image metadata array on success. 230 */ 203 231 function wp_read_image_metadata( $file ) { 204 232 if ( !file_exists( $file ) ) … … 207 235 list(,,$sourceImageType) = getimagesize( $file ); 208 236 209 // exif contains a bunch of data we'll probably never need formatted in ways that are difficult to use. 210 // We'll normalize it and just extract the fields that are likely to be useful. Fractions and numbers 211 // are converted to floats, dates to unix timestamps, and everything else to strings. 237 // exif contains a bunch of data we'll probably never need formatted in ways 238 // that are difficult to use. We'll normalize it and just extract the fields 239 // that are likely to be useful. Fractions and numbers are converted to 240 // floats, dates to unix timestamps, and everything else to strings. 212 241 $meta = array( 213 242 'aperture' => 0, … … 223 252 ); 224 253 225 // read iptc first, since it might contain data not available in exif such as caption, description etc 254 // read iptc first, since it might contain data not available in exif such 255 // as caption, description etc 226 256 if ( is_callable('iptcparse') ) { 227 257 getimagesize($file, $info); … … 232 262 elseif ( !empty($iptc['2#080'][0]) ) // byline 233 263 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); 234 if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) // created date eand time264 if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) // created date and time 235 265 $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]); 236 266 if ( !empty($iptc['2#120'][0]) ) // caption … … 259 289 $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] ); 260 290 } 261 / / FIXME: try other exif libraries if available291 /** @todo FIXME: try other exif libraries if available */ 262 292 263 293 return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType ); … … 265 295 } 266 296 267 // is the file a real image file? 297 /** 298 * Validate that file is an image. 299 * 300 * @since unknown 301 * 302 * @param string $path File path to test if valid image. 303 * @return bool True if valid image, false if not valid image. 304 */ 268 305 function file_is_valid_image($path) { 269 306 $size = @getimagesize($path); … … 271 308 } 272 309 273 // is the file an image suitable for displaying within a web page? 310 /** 311 * Validate that file is suitable for displaying within a web page. 312 * 313 * @since unknown 314 * @uses apply_filters() Calls 'file_is_displayable_image' on $result and $path. 315 * 316 * @param string $path File path to test. 317 * @return bool True if suitable, false if not suitable. 318 */ 274 319 function file_is_displayable_image($path) { 275 320 $info = @getimagesize($path);
Note: See TracChangeset
for help on using the changeset viewer.