Skip to content

Commit da4e0ec

Browse files
committed
Separate Large and Full image sizes. Props tellyworth. fixes WordPress#7151
git-svn-id: https://develop.svn.wordpress.org/trunk@8612 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1c05d81 commit da4e0ec

7 files changed

Lines changed: 88 additions & 30 deletions

File tree

wp-admin/css/media.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,17 @@ th { position: relative; }
8383
display: none;
8484
}
8585

86+
tr.image-size td {
87+
width: 460px;
88+
}
89+
tr.image-size div.image-size-item {
90+
float: left;
91+
width: 25%;
92+
margin: 0;
93+
}
8694
tr.image-size label {
8795
display: inline;
88-
margin: 0 1em 0 0;
96+
margin: 0 0 0 1em;
8997
}
9098
.pinkynail {
9199
max-width: 40px;
@@ -202,7 +210,7 @@ abbr.required {
202210
padding: 1em 0;
203211
}
204212

205-
#media-upload p.help {
213+
#media-upload p.help, #media-upload label.help {
206214
font-style: italic;
207215
font-weight: normal;
208216
}

wp-admin/includes/image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
9696
$metadata['file'] = $file;
9797

9898
// make thumbnails and other intermediate sizes
99-
$sizes = array('thumbnail', 'medium');
99+
$sizes = array('thumbnail', 'medium', 'large');
100100
$sizes = apply_filters('intermediate_image_sizes', $sizes);
101101

102102
foreach ($sizes as $size) {

wp-admin/includes/media.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,41 @@ function media_upload_library() {
520520
return wp_iframe( 'media_upload_library_form', $errors );
521521
}
522522

523+
function image_size_input_fields($post, $checked='') {
524+
525+
// get a list of the actual pixel dimensions of each possible intermediate version of this image
526+
$sizes = array();
527+
$size_names = array('thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size');
528+
529+
foreach ( $size_names as $size => $name) {
530+
$downsize = image_downsize($post->ID, $size);
531+
532+
// is this size selectable?
533+
$enabled = ( $downsize[3] || 'full' == $size );
534+
$css_id = "image-size-{$size}-{$post->ID}";
535+
// if $checked was not specified, default to the first available size that's bigger than a thumbnail
536+
if ( !$checked && $enabled && 'thumbnail' != $size )
537+
$checked = $size;
538+
539+
$html = "<div class='image-size-item'><input type='radio' ".( $enabled ? '' : "disabled='disabled'")."name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />";
540+
541+
$html .= "<label for='{$css_id}'>" . __($name). "</label>";
542+
// only show the dimensions if that choice is available
543+
if ( $enabled )
544+
$html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d&nbsp;&times;&nbsp;%d)"), $downsize[1], $downsize[2] ). "</label>";
545+
546+
$html .= '</div>';
547+
548+
$out[] = $html;
549+
}
550+
551+
return array(
552+
'label' => __('Size'),
553+
'input' => 'html',
554+
'html' => join("\n", $out),
555+
);
556+
}
557+
523558
function image_attachment_fields_to_edit($form_fields, $post) {
524559
if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
525560
$form_fields['post_title']['required'] = true;
@@ -529,8 +564,6 @@ function image_attachment_fields_to_edit($form_fields, $post) {
529564

530565
$form_fields['post_content']['label'] = __('Description');
531566

532-
$thumb = wp_get_attachment_thumb_url($post->ID);
533-
534567
$form_fields['align'] = array(
535568
'label' => __('Alignment'),
536569
'input' => 'html',
@@ -544,17 +577,7 @@ function image_attachment_fields_to_edit($form_fields, $post) {
544577
<input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' />
545578
<label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
546579
);
547-
$form_fields['image-size'] = array(
548-
'label' => __('Size'),
549-
'input' => 'html',
550-
'html' => "
551-
" . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumbnail' />
552-
<label for='image-size-thumb-$post->ID'>" . __('Thumbnail') . "</label>
553-
" : '' ) . "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-medium-$post->ID' value='medium' checked='checked' />
554-
<label for='image-size-medium-$post->ID'>" . __('Medium') . "</label>
555-
<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-full-$post->ID' value='full' />
556-
<label for='image-size-full-$post->ID'>" . __('Full size') . "</label>",
557-
);
580+
$form_fields['image-size'] = image_size_input_fields($post);
558581
}
559582
return $form_fields;
560583
}

wp-admin/includes/schema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ function populate_options() {
258258
add_option('enable_app', 0);
259259
add_option('enable_xmlrpc', 0);
260260

261+
// 2.7
262+
add_option('large_size_w', 1024);
263+
add_option('large_size_h', 1024);
264+
261265
// Delete unused options
262266
$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', 'autosave_interval', 'deactivated_plugins');
263267
foreach ($unusedoptions as $option) :

wp-admin/options-misc.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@
6262
<input name="medium_size_h" type="text" id="medium_size_h" value="<?php form_option('medium_size_h'); ?>" size="6" />
6363
</fieldset></td>
6464
</tr>
65+
<tr valign="top">
66+
<th scope="row"><?php _e('Large size') ?></th>
67+
<td><fieldset><legend class="hidden"><?php _e('Large size') ?></legend>
68+
<label for="large_size_w"><?php _e('Max Width'); ?></label>
69+
<input name="large_size_w" type="text" id="large_size_w" value="<?php form_option('large_size_w'); ?>" size="6" />
70+
<label for="large_size_h"><?php _e('Max Height'); ?></label>
71+
<input name="large_size_h" type="text" id="large_size_h" value="<?php form_option('large_size_h'); ?>" size="6" />
72+
</fieldset></td>
73+
</tr>
6574
</table>
6675

6776

wp-includes/media.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// scale down the default size of an image so it's a better fit for the editor and theme
66
function image_constrain_size_for_editor($width, $height, $size = 'medium') {
7+
global $content_width;
78

89
if ( is_array($size) ) {
910
$max_width = $size[0];
@@ -23,19 +24,23 @@ function image_constrain_size_for_editor($width, $height, $size = 'medium') {
2324
$max_height = intval(get_option('medium_size_h'));
2425
// if no width is set, default to the theme content width if available
2526
}
26-
else { // $size == 'full'
27-
// we're inserting a full size image into the editor. if it's a really big image we'll scale it down to fit reasonably
27+
elseif ( $size == 'large' ) {
28+
// we're inserting a large size image into the editor. if it's a really big image we'll scale it down to fit reasonably
2829
// within the editor itself, and within the theme's content width if it's known. the user can resize it in the editor
2930
// if they wish.
30-
if ( !empty($GLOBALS['content_width']) ) {
31-
$max_width = $GLOBALS['content_width'];
32-
}
33-
else
34-
$max_width = 500;
31+
$max_width = intval(get_option('large_size_w'));
32+
$max_height = intval(get_option('large_size_h'));
33+
if ( intval($content_width) > 0 )
34+
$max_width = min( intval($content_width), $max_width );
35+
}
36+
// $size == 'full' has no constraint
37+
else {
38+
$max_width = $width;
39+
$max_height = $height;
3540
}
3641

3742
list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size );
38-
43+
3944
return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
4045
}
4146

@@ -51,7 +56,8 @@ function image_hwstring($width, $height) {
5156

5257
// Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width.
5358
// 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.
54-
// returns an array($url, $width, $height)
59+
// returns an array($url, $width, $height, $is_intermediate)
60+
// $is_intermediate is true if $url is a resized image, false if it is the original
5561
function image_downsize($id, $size = 'medium') {
5662

5763
if ( !wp_attachment_is_image($id) )
@@ -60,6 +66,7 @@ function image_downsize($id, $size = 'medium') {
6066
$img_url = wp_get_attachment_url($id);
6167
$meta = wp_get_attachment_metadata($id);
6268
$width = $height = 0;
69+
$is_intermediate = false;
6370

6471
// plugins can use this to provide resize services
6572
if ( $out = apply_filters('image_downsize', false, $id, $size) )
@@ -70,22 +77,29 @@ function image_downsize($id, $size = 'medium') {
7077
$img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
7178
$width = $intermediate['width'];
7279
$height = $intermediate['height'];
80+
$is_intermediate = true;
7381
}
7482
elseif ( $size == 'thumbnail' ) {
7583
// fall back to the old thumbnail
7684
if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) {
7785
$img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
7886
$width = $info[0];
7987
$height = $info[1];
88+
$is_intermediate = true;
8089
}
8190
}
8291
if ( !$width && !$height && isset($meta['width'], $meta['height']) ) {
83-
// any other type: use the real image and constrain it
84-
list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size );
92+
// any other type: use the real image
93+
$width = $meta['width'];
94+
$height = $meta['height'];
8595
}
96+
97+
if ( $img_url) {
98+
// we have the actual image size, but might need to further constrain it if content_width is narrower
99+
list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size );
86100

87-
if ( $img_url)
88-
return array( $img_url, $width, $height );
101+
return array( $img_url, $width, $height, $is_intermediate );
102+
}
89103
return false;
90104

91105
}

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
*
1616
* @global int $wp_db_version
1717
*/
18-
$wp_db_version = 8539;
18+
$wp_db_version = 8585;
1919

2020
?>

0 commit comments

Comments
 (0)