Image size options from tellyworth. fixes #5933

git-svn-id: https://develop.svn.wordpress.org/trunk@6952 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-02-21 06:00:15 +00:00
parent a7e9b93bab
commit 6aacdf4c91
6 changed files with 161 additions and 37 deletions
+5
View File
@@ -109,6 +109,11 @@ form.media-upload-form {
background: url(../images/align-right.png) no-repeat center left;
}
.media-upload-form fieldset#image-size label {
display: inline;
margin: 0 1em 0 0;
}
.pinkynail {
max-width: 40px;
max-height: 40px;
+21 -10
View File
@@ -224,16 +224,27 @@ function get_udims( $width, $height) {
*
*/
function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
if ( $height <= $hmax && $width <= $wmax ){
//Image is smaller than max
return array( $width, $height);
} elseif ( $width / $height > $wmax / $hmax ) {
//Image Width will be greatest
return array( $wmax, (int) ($height / $width * $wmax ));
} else {
//Image Height will be greatest
return array( (int) ($width / $height * $hmax ), $hmax );
}
return wp_constrain_dimensions( $width, $height, $wmax, $hmax );
}
// same as wp_shrink_dimensions, except the max parameters are optional.
// if either width or height are empty, no constraint is applied on that dimension.
function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
if ( !$max_width and !$max_height )
return array( $current_width, $current_height );
$width_ratio = $height_ratio = 1.0;
if ( $max_width > 0 && $current_width > $max_width )
$width_ratio = $max_width / $current_width;
if ( $max_height > 0 && $current_height > $max_height )
$height_ratio = $max_height / $current_height;
// the smaller ratio is the one we need to fit it to the constraining box
$ratio = min( $width_ratio, $height_ratio );
return array( intval($current_width * $ratio), intval($current_height * $ratio) );
}
// convert a fraction string to a decimal
+15 -27
View File
@@ -131,6 +131,15 @@ jQuery(document).ready(function(){
<input type="radio" name="image-align" id="image-align-right" value="right" <?php if ($image_align == 'right') echo ' checked="checked"'; ?>/>
<label for="image-align-right" id="image-align-right-label"><?php _e('Right'); ?></label>
</fieldset>
<fieldset id="image-size">
<legend><?php _e('Size'); ?></legend>
<input type="radio" name="image-size" id="image-size-thumb" value="thumb" <?php if ($image_size == 'thumb') echo ' checked="checked"'; ?>/>
<label for="image-size-thumb" id="image-size-thumb-label"><?php _e('Thumbnail'); ?></label>
<input type="radio" name="image-size" id="image-size-medium" value="medium" <?php if ($image_size == 'medium' || !$image_size) echo ' checked="checked"'; ?>/>
<label for="image-size-medium" id="image-size-medium-label"><?php _e('Medium'); ?></label>
<input type="radio" name="image-size" id="image-size-full" value="full" <?php if ($image_size == 'full') echo ' checked="checked"'; ?>/>
<label for="image-size-full" id="image-size-full-label"><?php _e('Full size'); ?></label>
</fieldset>
<p>
<button name="image-add" id="image-add" class="button-ok" value="1"><?php _e('Add Image'); ?></button>
<a href="#" onClick="return top.tb_remove();" id="image-cancel" class="button-cancel"><?php _e('Cancel'); ?></a>
@@ -174,7 +183,7 @@ function image_upload_handler() {
if ( is_wp_error($id) )
wp_iframe( 'image_upload_form', get_option('siteurl') . '/wp-admin/media-upload.php?type=image', $_POST, $id );
else {
media_send_to_editor(get_image_send_to_editor($id, $_POST['image-alt'], $_POST['image-title'], $_POST['image-align'], $_POST['image-url']));
media_send_to_editor(get_image_send_to_editor($id, $_POST['image-alt'], $_POST['image-title'], $_POST['image-align'], $_POST['image-url'], true, $_POST['image-size']));
}
}
}
@@ -217,37 +226,16 @@ EOF;
add_filter('async_upload_image', 'async_image_callback');
// 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) {
// pick a reasonable default width for the image
// $content_width might be set in the theme's functions.php
if ( !empty($GLOBALS['content_width']) )
$max_width = $GLOBALS['content_width'];
else
$max_width = 500;
$max_width = apply_filters( 'editor_max_image_width', $max_width );
$max_height = apply_filters( 'editor_max_image_height', $max_width );
return wp_shrink_dimensions( $width, $height, $max_width, $max_height );
}
function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false) {
$img_src = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id);
$hwstring = '';
if ( isset($meta['width'], $meta['height']) ) {
list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'] );
$hwstring = ' width="'.intval($width).'" height="'.intval($height).'"';
}
$html = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"'.$hwstring.' class="align-'.attribute_escape($align).'" />';
$html = get_image_tag($id, $alt, $title, $align, $rel, $size);
$rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
if ( $url )
$html = "<a href='".attribute_escape($url)."'$rel>$html</a>";
elseif ( $size == 'thumb' || $size == 'medium' )
$html = '<a href="'.get_attachment_link($id).'"'.$rel.'>'.$html.'</a>';
$html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
@@ -392,7 +380,7 @@ function media_buttons() { // just a placeholder for now
$multimedia_upload_iframe_src = apply_filters('multimedia_upload_iframe_src', $multimedia_upload_iframe_src);
$out = <<<EOF
<a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=480" class="thickbox"><img src='images/media-button-image.gif' alt='' /></a>
<a href="{$image_upload_iframe_src}&TB_iframe=true&height=550&width=480" class="thickbox"><img src='images/media-button-image.gif' alt='' /></a>
<a href="{$multimedia_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-gallery.gif' alt='' /></a>
<a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-video.gif' alt='' /></a>
<a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-music.gif' alt='' /></a>
+24
View File
@@ -57,6 +57,30 @@ endforeach;
</tr>
</table>
<h3><?php _e('Image sizes') ?></h3>
<p><?php _e('The sizes listed below determine the maximum dimensions to use when inserting an image into the body of a post.'); ?></p>
<table class="niceblue">
<tr valign="top">
<th scope="row"><?php _e('Thumbnail size:') ?></th>
<td>
<label for="thumbnail_size_w"><?php _e('Width:'); ?></label>
<input name="thumbnail_size_w" type="text" id="thumbnail_size_w" value="<?php form_option('thumbnail_size_w'); ?>" size="6" />
<label for="thumbnail_size_h"><?php _e('Height:'); ?></label>
<input name="thumbnail_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('thumbnail_size_h'); ?>" size="6" />
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Medium size:') ?></th>
<td>
<label for="medium_size_w"><?php _e('Width:'); ?></label>
<input name="medium_size_w" type="text" id="medium_size_w" value="<?php form_option('medium_size_w'); ?>" size="6" />
<label for="medium_size_h"><?php _e('Height:'); ?></label>
<input name="medium_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('medium_size_h'); ?>" size="6" />
</td>
</tr>
</table>
<h3><?php _e('Post via e-mail') ?></h3>
<p><?php printf(__('To post to WordPress by e-mail you must set up a secret e-mail account with POP3 access. Any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret. Here are three random strings you could use: <code>%s</code>, <code>%s</code>, <code>%s</code>.'), wp_generate_password(), wp_generate_password(), wp_generate_password()) ?></p>