Ticket #6074: intermediate-image-sizing-r7133-3.patch
| File intermediate-image-sizing-r7133-3.patch, 14.3 KB (added by , 19 years ago) |
|---|
-
wordpress/wp-includes/post-template.php
389 389 390 390 $file = get_attached_file( $post->ID ); 391 391 392 if ( !$fullsize && $ thumbfile = wp_get_attachment_thumb_file( $post->ID ) ) {392 if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) { 393 393 // We have a thumbnail desired, specified and existing 394 394 395 $src = wp_get_attachment_thumb_url( $post->ID ); 396 $src_file = $thumbfile; 395 $src_file = basename($src); 397 396 $class = 'attachmentthumb'; 398 397 } elseif ( wp_attachment_is_image( $post->ID ) ) { 399 398 // We have an image without a thumbnail -
wordpress/wp-includes/post.php
2128 2128 2129 2129 if ( $file ) 2130 2130 update_attached_file( $post_ID, $file ); 2131 2131 2132 2132 clean_post_cache($post_ID); 2133 2133 2134 2134 if ( $update) { … … 2316 2316 return false; 2317 2317 if ( !$url = wp_get_attachment_url( $post->ID ) ) 2318 2318 return false; 2319 2320 $sized = image_downsize( $post_id, 'thumbnail' ); 2321 if ( $sized ) 2322 return $sized[0]; 2319 2323 2320 2324 if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) 2321 2325 return false; -
wordpress/wp-includes/media.php
48 48 } 49 49 50 50 // Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width. 51 // The URL might be the original image, or it might be a resized version. 51 // The URL might be the original image, or it might be a resized version. This function won't create a new resized copy, it will just return an already resized one if it exists. 52 52 // returns an array($url, $width, $height) 53 53 function image_downsize($id, $size = 'medium') { 54 54 … … 60 60 if ( $out = apply_filters('image_downsize', false, $id, $size) ) 61 61 return $out; 62 62 63 if ( $size == 'thumb' ) { 64 // thumbnail: use the thumb as the displayed image, and constrain based on its dimensions 65 $thumb_path = wp_get_attachment_thumb_file($id); 66 // the actual thumbnail size isn't stored so we'll have to calculate it 67 if ( $thumb_path && ($info = getimagesize($thumb_path)) ) { 68 list( $width, $height ) = image_constrain_size_for_editor( $info[0], $info[1], $size ); 69 $img_url = wp_get_attachment_thumb_url($id); 63 // try for a new style intermediate size 64 if ( $intermediate = image_get_intermediate_size($id, $size) ) { 65 $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url); 66 $width = $intermediate['width']; 67 $height = $intermediate['height']; 68 } 69 elseif ( $size == 'thumbnail' ) { 70 // fall back to the old thumbnail 71 if ( $thumb_file = wp_get_attachment_thumb_file() && $info = getimagesize($thumb_file) ) { 72 $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url); 73 $width = $info[0]; 74 $height = $info[1]; 70 75 } 71 // this could be improved to provide a default thumbnail if one doesn't exist72 76 } 73 77 elseif ( isset($meta['width'], $meta['height']) ) { 74 78 // any other type: use the real image and constrain it … … 226 230 return $destfilename; 227 231 } 228 232 233 // resize an image to make a thumbnail or intermediate size, and return metadata describing the new copy 234 // returns false if no image was created 235 function image_make_intermediate_size($file, $width, $height, $crop=false) { 236 if ( $width || $height ) { 237 $resized_file = image_resize($file, $width, $height, $crop); 238 if ( $resized_file && $info = getimagesize($resized_file) ) { 239 return array( 240 'file' => basename( $resized_file ), 241 'width' => $info[0], 242 'height' => $info[1], 243 ); 244 } 245 } 246 return false; 247 } 248 249 function image_get_intermediate_size($post_id, $size='thumbnail') { 250 if ( !$imagedata = wp_get_attachment_metadata( $post_id ) ) 251 return false; 252 253 if ( empty($imagedata['sizes'][$size]) ) 254 return false; 255 256 return $imagedata['sizes'][$size]; 257 } 258 259 229 260 ?> 261 No newline at end of file -
wordpress/wp-admin/includes/schema.php
244 244 add_option('show_avatars', '1'); 245 245 add_option('avatar_rating', 'G'); 246 246 add_option('upload_url_path', ''); 247 add_option('thumbnail_size_w', 150); 248 add_option('thumbnail_size_h', 150); 249 add_option('thumbnail_crop', 1); 250 add_option('medium_size_w', ''); 251 add_option('medium_size_h', ''); 247 252 248 253 // Delete unused options 249 254 $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing'); -
wordpress/wp-admin/includes/media.php
55 55 $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; 56 56 if ( $url ) 57 57 $html = "<a href='".attribute_escape($url)."'$rel>$html</a>"; 58 elseif ( $size == 'thumb ' || $size == 'medium' )58 elseif ( $size == 'thumbnail' || $size == 'medium' ) 59 59 $html = '<a href="'.get_attachment_link($id).'"'.$rel.'>'.$html.'</a>'; 60 60 61 61 $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url ); … … 467 467 'label' => __('Size'), 468 468 'input' => 'html', 469 469 'html' => " 470 " . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumb ' />470 " . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumbnail' /> 471 471 <label for='image-size-thumb-$post->ID'>" . __('Thumbnail') . "</label> 472 472 " : '' ) . "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-medium-$post->ID' value='medium' checked='checked' /> 473 473 <label for='image-size-medium-$post->ID'>" . __('Medium') . "</label> -
wordpress/wp-admin/includes/image.php
17 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. 18 18 */ 19 19 function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) { 20 if ( ctype_digit( $file ) ) // Handle int as attachment ID 21 $file = get_attached_file( $file ); 22 23 $image = wp_load_image( $file ); 24 25 if ( !is_resource( $image ) ) 26 return $image; 27 28 list($sourceImageWidth, $sourceImageHeight, $sourceImageType) = getimagesize( $file ); 29 30 if ( function_exists( 'imageantialias' )) 31 imageantialias( $image, true ); 32 33 list($image_new_width, $image_new_height) = wp_shrink_dimensions( $sourceImageWidth, $sourceImageHeight, $max_side, $max_side); 34 35 $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height); 36 37 // preserve PNG transparency 38 if ( IMAGETYPE_PNG == $sourceImageType && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { 39 imagealphablending( $thumbnail, false); 40 imagesavealpha( $thumbnail, true); 41 } 42 43 imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $sourceImageWidth, $sourceImageHeight ); 44 45 imagedestroy( $image ); // Free up memory 46 47 // If no filters change the filename, we'll do a default transformation. 48 if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) ) 49 $thumb = preg_replace( '!(\.[^.]+)?$!', '.thumbnail$1', basename( $file ), 1 ); 50 51 $thumbpath = str_replace( basename( $file ), $thumb, $file ); 52 53 switch( $sourceImageType ){ 54 default: // We'll create a Jpeg if we cant use its native file format 55 $thumb = preg_replace( '/\\.[^\\.]+$/', '.jpg', $thumb ); //Change file extension to Jpg 56 case IMAGETYPE_JPEG: 57 if (!imagejpeg( $thumbnail, $thumbpath ) ) 58 return __( 'Thumbnail path invalid' ); 59 break; 60 case IMAGETYPE_GIF: 61 if (!imagegif( $thumbnail, $thumbpath ) ) 62 return __( 'Thumbnail path invalid' ); 63 break; 64 case IMAGETYPE_PNG: 65 if (!imagepng( $thumbnail, $thumbpath ) ) 66 return __( 'Thumbnail path invalid' ); 67 break; 68 } 69 70 imagedestroy( $thumbnail ); // Free up memory 71 72 // Set correct file permissions 73 $stat = stat( dirname( $thumbpath )); 74 $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits 75 @ chmod( $thumbpath, $perms ); 76 20 21 $thumbpath = image_resize( $file, $max_side, $max_side ); 77 22 return apply_filters( 'wp_create_thumbnail', $thumbpath ); 78 23 } 79 24 … … 142 87 $attachment = get_post( $attachment_id ); 143 88 144 89 $metadata = array(); 145 if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) {90 if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { 146 91 $imagesize = getimagesize( $file ); 147 92 $metadata['width'] = $imagesize[0]; 148 93 $metadata['height'] = $imagesize[1]; … … 150 95 $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'"; 151 96 $metadata['file'] = $file; 152 97 153 $max = apply_filters( 'wp_thumbnail_creation_size_limit', absint( WP_MEMORY_LIMIT ) * 1024 * 1024, $attachment_id, $file ); 154 155 if ( $max < 0 || $metadata['width'] * $metadata['height'] < $max ) { 156 $max_side = apply_filters( 'wp_thumbnail_max_side_length', 140, $attachment_id, $file ); 157 $thumb = wp_create_thumbnail( $file, $max_side ); 158 if ( @file_exists($thumb) ) 159 $metadata['thumb'] = basename($thumb); 98 // make thumbnails and other intermediate sizes 99 $sizes = array('thumbnail', 'medium'); 100 $sizes = apply_filters('intermediate_image_sizes', $sizes); 101 102 foreach ($sizes as $size) { 103 $resized = image_make_intermediate_size( $file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") ); 104 if ( $resized ) 105 $metadata['sizes'][$size] = $resized; 160 106 } 161 107 162 108 // fetch additional metadata from exif/iptc 163 109 $image_meta = wp_read_image_metadata( $file ); 164 110 if ($image_meta) 165 111 $metadata['image_meta'] = $image_meta; 166 112 167 113 } 114 var_dump($metadata); 168 115 return apply_filters( 'wp_generate_attachment_metadata', $metadata ); 169 116 } 170 117 … … 309 256 310 257 } 311 258 259 // is the file a real image file? 260 function file_is_valid_image($path) { 261 $size = @getimagesize($path); 262 return !empty($size); 263 } 312 264 265 // is the file an image suitable for displaying within a web page? 266 function file_is_displayable_image($path) { 267 $info = @getimagesize($path); 268 if ( empty($info) ) 269 $result = false; 270 elseif ( !in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) ) 271 // only gif, jpeg and png images can reliably be displayed 272 $result = false; 273 elseif ( $info['channels'] > 0 && $info['channels'] != 3 ) { 274 // some web browsers can't display cmyk or grayscale jpegs 275 $result = false; 276 } 277 else 278 $result = true; 279 280 return apply_filters('file_is_displayable_image', $result, $path); 281 } 282 313 283 ?> -
wordpress/wp-admin/includes/upload.php
59 59 $thumb_base = wp_mime_type_icon(); 60 60 if ( $thumb_base ) { 61 61 $thumb_rel = wp_make_link_relative( $thumb_base ); 62 var_dump("thumb_base = $thumb_base", "thumb_rel = $thumb_rel"); 62 63 $thumb_base = str_replace( $thumb_rel, '', $thumb_base ); 63 64 $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$thumb_rel' />\n"; 64 65 $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-base-$id' id='attachment-thumb-url-base-$id' value='$thumb_base' />\n"; -
wordpress/wp-admin/options-writing.php
68 68 <input name="thumbnail_size_w" type="text" id="thumbnail_size_w" value="<?php form_option('thumbnail_size_w'); ?>" size="6" /> 69 69 <label for="thumbnail_size_h"><?php _e('Height'); ?></label> 70 70 <input name="thumbnail_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('thumbnail_size_h'); ?>" size="6" /> 71 <input name="thumbnail_crop" type="checkbox" id="thumbnail_crop" value="1" <?php checked('1', get_option('thumbnail_crop')); ?>/> 72 <label for="thumbnail_crop"><?php _e('Crop to size'); ?></label> 71 73 </td> 72 74 </tr> 73 75 <tr valign="top"> … … 134 136 135 137 <p class="submit"> 136 138 <input type="hidden" name="action" value="update" /> 137 <input type="hidden" name="page_options" value="default_post_edit_rows,use_smilies,ping_sites,mailserver_url,mailserver_port,mailserver_login,mailserver_pass,default_category,default_email_category,use_balanceTags,default_link_category " />139 <input type="hidden" name="page_options" value="default_post_edit_rows,use_smilies,ping_sites,mailserver_url,mailserver_port,mailserver_login,mailserver_pass,default_category,default_email_category,use_balanceTags,default_link_category,thumbnail_size_w,thumbnail_size_h,thumbnail_crop,medium_size_w,medium_size_h" /> 138 140 <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> 139 141 </p> 140 142 </form>
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)