Sanity checks on image metadata to avoid warnings, etc.

fixes #23733. props wonderboymusic.

git-svn-id: http://core.svn.wordpress.org/trunk@23873 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-03-29 20:51:35 +00:00
parent 925e7f5bd6
commit fec4b66f5b
5 changed files with 30 additions and 21 deletions

View File

@ -663,8 +663,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
list( $width, $height, $type, $attr ) = getimagesize( $file );
} else {
$data = wp_get_attachment_metadata( $attachment_id );
$height = $data[ 'height' ];
$width = $data[ 'width' ];
$height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0;
$width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0;
unset( $data );
}

View File

@ -13,7 +13,7 @@ function wp_image_editor($post_id, $msg = false) {
$sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']);
$note = '';
if ( is_array($meta) && isset($meta['width']) )
if ( isset( $meta['width'], $meta['height'] ) )
$big = max( $meta['width'], $meta['height'] );
else
die( __('Image data does not exist. Please re-upload the image.') );
@ -21,8 +21,9 @@ function wp_image_editor($post_id, $msg = false) {
$sizer = $big > 400 ? 400 / $big : 1;
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
$can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig'])
&& $backup_sizes['full-orig']['file'] != basename($meta['file']);
$can_restore = false;
if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) )
$can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] );
if ( $msg ) {
if ( isset($msg->error) )
@ -63,8 +64,8 @@ function wp_image_editor($post_id, $msg = false) {
<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo $meta['width']; ?>" />
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo $meta['height']; ?>" />
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>?action=imgedit-preview&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;rand=<?php echo rand(1, 99999); ?>" />
@ -82,9 +83,11 @@ function wp_image_editor($post_id, $msg = false) {
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php _e('Scale Image'); ?></strong></a>
<div class="imgedit-help">
<p><?php _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that if you make the image larger it may become fuzzy.'); ?></p>
<?php if ( isset( $meta['width'], $meta['height'] ) ): ?>
<p><?php printf( __('Original dimensions %s'), $meta['width'] . '&times;' . $meta['height'] ); ?></p>
<?php endif ?>
<div class="imgedit-submit">
<span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo $meta['width']; ?>" />&times;<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo $meta['height']; ?>" />
<span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />&times;<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span></span>
<input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" />
</div>
@ -499,7 +502,7 @@ function wp_restore_image($post_id) {
$delpath = apply_filters('wp_delete_file', $file);
@unlink($delpath);
}
} else {
} elseif ( isset( $meta['width'], $meta['height'] ) ) {
$backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
}
}

View File

@ -1127,7 +1127,7 @@ function get_media_item( $attachment_id, $args = null ) {
$media_dims = '';
$meta = wp_get_attachment_metadata( $post->ID );
if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
if ( isset( $meta['width'], $meta['height'] ) )
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
$media_dims = apply_filters( 'media_meta', $media_dims, $post );
@ -2368,7 +2368,7 @@ function attachment_submitbox_metadata() {
$media_dims = '';
$meta = wp_get_attachment_metadata( $post->ID );
if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
if ( isset( $meta['width'], $meta['height'] ) )
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
$media_dims = apply_filters( 'media_meta', $media_dims, $post );

View File

@ -164,7 +164,7 @@ function image_downsize($id, $size = 'medium') {
$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
$width = $meta['width'];
$height = $meta['height'];
@ -780,7 +780,10 @@ function gallery_shortcode($attr) {
foreach ( $attachments as $id => $attachment ) {
$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$image_meta = wp_get_attachment_metadata( $id );
$orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
$orientation = '';
if ( isset( $image_meta['height'], $image_meta['width'] ) )
$orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
$output .= "<{$itemtag} class='gallery-item'>";
$output .= "
@ -1626,12 +1629,13 @@ function wp_prepare_attachment_for_js( $attachment ) {
}
}
$sizes['full'] = array(
'height' => $meta['height'],
'width' => $meta['width'],
'url' => $attachment_url,
'orientation' => $meta['height'] > $meta['width'] ? 'portrait' : 'landscape',
);
$sizes['full'] = array( 'url' => $attachment_url );
if ( isset( $meta['height'], $meta['width'] ) ) {
$sizes['full']['height'] = $meta['height'];
$sizes['full']['width'] = $meta['width'];
$sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape';
}
$response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
}

View File

@ -1013,8 +1013,10 @@ function get_uploaded_header_images() {
$header_images[$header_index]['attachment_id'] = $header->ID;
$header_images[$header_index]['url'] = $url;
$header_images[$header_index]['thumbnail_url'] = $url;
$header_images[$header_index]['width'] = $header_data['width'];
$header_images[$header_index]['height'] = $header_data['height'];
if ( isset( $header_data['width'] ) )
$header_images[$header_index]['width'] = $header_data['width'];
if ( isset( $header_data['height'] ) )
$header_images[$header_index]['height'] = $header_data['height'];
}
return $header_images;