Separate Large and Full image sizes. Props tellyworth. fixes #7151

git-svn-id: http://svn.automattic.com/wordpress/trunk@8612 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-11 03:54:26 +00:00
parent efb38685f8
commit ff7b8ffe1b
7 changed files with 88 additions and 30 deletions

View File

@ -83,9 +83,17 @@ th { position: relative; }
display: none; display: none;
} }
tr.image-size td {
width: 460px;
}
tr.image-size div.image-size-item {
float: left;
width: 25%;
margin: 0;
}
tr.image-size label { tr.image-size label {
display: inline; display: inline;
margin: 0 1em 0 0; margin: 0 0 0 1em;
} }
.pinkynail { .pinkynail {
max-width: 40px; max-width: 40px;
@ -202,7 +210,7 @@ abbr.required {
padding: 1em 0; padding: 1em 0;
} }
#media-upload p.help { #media-upload p.help, #media-upload label.help {
font-style: italic; font-style: italic;
font-weight: normal; font-weight: normal;
} }

View File

@ -96,7 +96,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
$metadata['file'] = $file; $metadata['file'] = $file;
// make thumbnails and other intermediate sizes // make thumbnails and other intermediate sizes
$sizes = array('thumbnail', 'medium'); $sizes = array('thumbnail', 'medium', 'large');
$sizes = apply_filters('intermediate_image_sizes', $sizes); $sizes = apply_filters('intermediate_image_sizes', $sizes);
foreach ($sizes as $size) { foreach ($sizes as $size) {

View File

@ -520,6 +520,41 @@ function media_upload_library() {
return wp_iframe( 'media_upload_library_form', $errors ); return wp_iframe( 'media_upload_library_form', $errors );
} }
function image_size_input_fields($post, $checked='') {
// get a list of the actual pixel dimensions of each possible intermediate version of this image
$sizes = array();
$size_names = array('thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size');
foreach ( $size_names as $size => $name) {
$downsize = image_downsize($post->ID, $size);
// is this size selectable?
$enabled = ( $downsize[3] || 'full' == $size );
$css_id = "image-size-{$size}-{$post->ID}";
// if $checked was not specified, default to the first available size that's bigger than a thumbnail
if ( !$checked && $enabled && 'thumbnail' != $size )
$checked = $size;
$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'" : '') ." />";
$html .= "<label for='{$css_id}'>" . __($name). "</label>";
// only show the dimensions if that choice is available
if ( $enabled )
$html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d&nbsp;&times;&nbsp;%d)"), $downsize[1], $downsize[2] ). "</label>";
$html .= '</div>';
$out[] = $html;
}
return array(
'label' => __('Size'),
'input' => 'html',
'html' => join("\n", $out),
);
}
function image_attachment_fields_to_edit($form_fields, $post) { function image_attachment_fields_to_edit($form_fields, $post) {
if ( substr($post->post_mime_type, 0, 5) == 'image' ) { if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
$form_fields['post_title']['required'] = true; $form_fields['post_title']['required'] = true;
@ -529,8 +564,6 @@ function image_attachment_fields_to_edit($form_fields, $post) {
$form_fields['post_content']['label'] = __('Description'); $form_fields['post_content']['label'] = __('Description');
$thumb = wp_get_attachment_thumb_url($post->ID);
$form_fields['align'] = array( $form_fields['align'] = array(
'label' => __('Alignment'), 'label' => __('Alignment'),
'input' => 'html', 'input' => 'html',
@ -544,17 +577,7 @@ function image_attachment_fields_to_edit($form_fields, $post) {
<input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' /> <input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' />
<label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n", <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
); );
$form_fields['image-size'] = array( $form_fields['image-size'] = image_size_input_fields($post);
'label' => __('Size'),
'input' => 'html',
'html' => "
" . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumbnail' />
<label for='image-size-thumb-$post->ID'>" . __('Thumbnail') . "</label>
" : '' ) . "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-medium-$post->ID' value='medium' checked='checked' />
<label for='image-size-medium-$post->ID'>" . __('Medium') . "</label>
<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-full-$post->ID' value='full' />
<label for='image-size-full-$post->ID'>" . __('Full size') . "</label>",
);
} }
return $form_fields; return $form_fields;
} }

View File

@ -258,6 +258,10 @@ function populate_options() {
add_option('enable_app', 0); add_option('enable_app', 0);
add_option('enable_xmlrpc', 0); add_option('enable_xmlrpc', 0);
// 2.7
add_option('large_size_w', 1024);
add_option('large_size_h', 1024);
// Delete unused options // Delete unused options
$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'); $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');
foreach ($unusedoptions as $option) : foreach ($unusedoptions as $option) :

View File

@ -62,6 +62,15 @@ include('admin-header.php');
<input name="medium_size_h" type="text" id="medium_size_h" value="<?php form_option('medium_size_h'); ?>" size="6" /> <input name="medium_size_h" type="text" id="medium_size_h" value="<?php form_option('medium_size_h'); ?>" size="6" />
</fieldset></td> </fieldset></td>
</tr> </tr>
<tr valign="top">
<th scope="row"><?php _e('Large size') ?></th>
<td><fieldset><legend class="hidden"><?php _e('Large size') ?></legend>
<label for="large_size_w"><?php _e('Max Width'); ?></label>
<input name="large_size_w" type="text" id="large_size_w" value="<?php form_option('large_size_w'); ?>" size="6" />
<label for="large_size_h"><?php _e('Max Height'); ?></label>
<input name="large_size_h" type="text" id="large_size_h" value="<?php form_option('large_size_h'); ?>" size="6" />
</fieldset></td>
</tr>
</table> </table>

View File

@ -4,6 +4,7 @@
// scale down the default size of an image so it's a better fit for the editor and theme // scale down the default size of an image so it's a better fit for the editor and theme
function image_constrain_size_for_editor($width, $height, $size = 'medium') { function image_constrain_size_for_editor($width, $height, $size = 'medium') {
global $content_width;
if ( is_array($size) ) { if ( is_array($size) ) {
$max_width = $size[0]; $max_width = $size[0];
@ -23,19 +24,23 @@ function image_constrain_size_for_editor($width, $height, $size = 'medium') {
$max_height = intval(get_option('medium_size_h')); $max_height = intval(get_option('medium_size_h'));
// if no width is set, default to the theme content width if available // if no width is set, default to the theme content width if available
} }
else { // $size == 'full' elseif ( $size == 'large' ) {
// 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 // 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
// within the editor itself, and within the theme's content width if it's known. the user can resize it in the editor // within the editor itself, and within the theme's content width if it's known. the user can resize it in the editor
// if they wish. // if they wish.
if ( !empty($GLOBALS['content_width']) ) { $max_width = intval(get_option('large_size_w'));
$max_width = $GLOBALS['content_width']; $max_height = intval(get_option('large_size_h'));
} if ( intval($content_width) > 0 )
else $max_width = min( intval($content_width), $max_width );
$max_width = 500; }
// $size == 'full' has no constraint
else {
$max_width = $width;
$max_height = $height;
} }
list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size ); list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size );
return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
} }
@ -51,7 +56,8 @@ function image_hwstring($width, $height) {
// Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width. // Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width.
// 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. // 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.
// returns an array($url, $width, $height) // returns an array($url, $width, $height, $is_intermediate)
// $is_intermediate is true if $url is a resized image, false if it is the original
function image_downsize($id, $size = 'medium') { function image_downsize($id, $size = 'medium') {
if ( !wp_attachment_is_image($id) ) if ( !wp_attachment_is_image($id) )
@ -60,6 +66,7 @@ function image_downsize($id, $size = 'medium') {
$img_url = wp_get_attachment_url($id); $img_url = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id); $meta = wp_get_attachment_metadata($id);
$width = $height = 0; $width = $height = 0;
$is_intermediate = false;
// plugins can use this to provide resize services // plugins can use this to provide resize services
if ( $out = apply_filters('image_downsize', false, $id, $size) ) if ( $out = apply_filters('image_downsize', false, $id, $size) )
@ -70,6 +77,7 @@ function image_downsize($id, $size = 'medium') {
$img_url = str_replace(basename($img_url), $intermediate['file'], $img_url); $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
$width = $intermediate['width']; $width = $intermediate['width'];
$height = $intermediate['height']; $height = $intermediate['height'];
$is_intermediate = true;
} }
elseif ( $size == 'thumbnail' ) { elseif ( $size == 'thumbnail' ) {
// fall back to the old thumbnail // fall back to the old thumbnail
@ -77,15 +85,21 @@ function image_downsize($id, $size = 'medium') {
$img_url = str_replace(basename($img_url), basename($thumb_file), $img_url); $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
$width = $info[0]; $width = $info[0];
$height = $info[1]; $height = $info[1];
$is_intermediate = true;
} }
} }
if ( !$width && !$height && isset($meta['width'], $meta['height']) ) { if ( !$width && !$height && isset($meta['width'], $meta['height']) ) {
// any other type: use the real image and constrain it // any other type: use the real image
list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size ); $width = $meta['width'];
$height = $meta['height'];
} }
if ( $img_url) {
// we have the actual image size, but might need to further constrain it if content_width is narrower
list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size );
if ( $img_url) return array( $img_url, $width, $height, $is_intermediate );
return array( $img_url, $width, $height ); }
return false; return false;
} }

View File

@ -15,6 +15,6 @@ $wp_version = '2.7-bleeding';
* *
* @global int $wp_db_version * @global int $wp_db_version
*/ */
$wp_db_version = 8539; $wp_db_version = 8585;
?> ?>