Changeset 7130 for trunk/wp-includes/media.php
- Timestamp:
- 03/02/2008 08:17:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/media.php
r7043 r7130 5 5 // scale down the default size of an image so it's a better fit for the editor and theme 6 6 function image_constrain_size_for_editor($width, $height, $size = 'medium') { 7 7 8 8 if ( $size == 'thumb' ) { 9 9 $max_width = intval(get_option('thumbnail_size_w')); … … 34 34 35 35 list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size ); 36 36 37 37 return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); 38 38 } … … 52 52 // returns an array($url, $width, $height) 53 53 function image_downsize($id, $size = 'medium') { 54 54 55 55 $img_url = wp_get_attachment_url($id); 56 56 $meta = wp_get_attachment_metadata($id); 57 57 $width = $height = 0; 58 58 59 59 // plugins can use this to provide resize services 60 60 if ( $out = apply_filters('image_downsize', false, $id, $size) ) 61 61 return $out; 62 62 63 63 if ( $size == 'thumb' ) { 64 64 // thumbnail: use the thumb as the displayed image, and constrain based on its dimensions … … 75 75 list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size ); 76 76 } 77 77 78 78 return array( $img_url, $width, $height ); 79 79 80 80 } 81 81 … … 98 98 if ( !$max_width and !$max_height ) 99 99 return array( $current_width, $current_height ); 100 100 101 101 $width_ratio = $height_ratio = 1.0; 102 102 103 103 if ( $max_width > 0 && $current_width > $max_width ) 104 104 $width_ratio = $max_width / $current_width; 105 105 106 106 if ( $max_height > 0 && $current_height > $max_height ) 107 107 $height_ratio = $max_height / $current_height; 108 108 109 109 // the smaller ratio is the one we need to fit it to the constraining box 110 110 $ratio = min( $width_ratio, $height_ratio ); 111 111 112 112 return array( intval($current_width * $ratio), intval($current_height * $ratio) ); 113 113 } … … 116 116 // if $crop is true, the largest matching central portion of the image will be cropped out and resized to the required size 117 117 function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=false) { 118 118 119 119 if ($orig_w <= 0 || $orig_h <= 0) 120 120 return false; … … 122 122 if ($dest_w <= 0 && $dest_h <= 0) 123 123 return false; 124 124 125 125 if ( $crop ) { 126 126 // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h … … 136 136 137 137 $size_ratio = max($new_w / $orig_w, $new_h / $orig_h); 138 138 139 139 $crop_w = ceil($new_w / $size_ratio); 140 140 $crop_h = ceil($new_h / $size_ratio); … … 147 147 $crop_w = $orig_w; 148 148 $crop_h = $orig_h; 149 149 150 150 $s_x = 0; 151 151 $s_y = 0; 152 152 153 153 list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h ); 154 154 } 155 155 156 156 // if the resulting image would be the same size or larger we don't want to resize it 157 157 if ($new_w >= $orig_w && $new_h >= $orig_h) … … 176 176 return $dims; 177 177 list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; 178 178 179 179 $newimage = imagecreatetruecolor( $dst_w, $dst_h); 180 180
Note: See TracChangeset
for help on using the changeset viewer.