]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/image.php
Wordpress 2.9
[autoinstalls/wordpress.git] / wp-admin / includes / image.php
index c0632ac5c2d2ad4f6eb9e36421ff48dce81891c8..903bd5fe17fc72eca02e02ebb1c2ff5cf4a2f757 100644 (file)
@@ -49,7 +49,7 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_
        if ( !is_resource( $src ))
                return $src;
 
-       $dst = imagecreatetruecolor( $dst_w, $dst_h );
+       $dst = wp_imagecreatetruecolor( $dst_w, $dst_h );
 
        if ( $src_abs ) {
                $src_w -= $src_x;
@@ -75,7 +75,7 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_
 }
 
 /**
- * Generate post image attachment meta data.
+ * Generate post thumbnail attachment meta data.
  *
  * @since 2.1.0
  *
@@ -88,40 +88,55 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
 
        $metadata = array();
        if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
-               $full_path_file = $file;
-               $imagesize = getimagesize( $full_path_file );
+               $imagesize = getimagesize( $file );
                $metadata['width'] = $imagesize[0];
                $metadata['height'] = $imagesize[1];
                list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']);
                $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
 
                // Make the file path relative to the upload dir
-               if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory
-                       if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path
-                               $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path
-                               $file = ltrim($file, '/');
-                       }
-               }
-               $metadata['file'] = $file;
+               $metadata['file'] = _wp_relative_upload_path($file);
 
                // make thumbnails and other intermediate sizes
-               $sizes = array('thumbnail', 'medium', 'large');
-               $sizes = apply_filters('intermediate_image_sizes', $sizes);
+               global $_wp_additional_image_sizes;
+               $temp_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
+               if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
+                       $temp_sizes = array_merge( $temp_sizes, array_keys( $_wp_additional_image_sizes ) );
+
+               $temp_sizes = apply_filters( 'intermediate_image_sizes', $temp_sizes );
+
+               foreach ( $temp_sizes as $s ) {
+                       $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
+                       if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
+                               $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
+                       else
+                               $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
+                       if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
+                               $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
+                       else
+                               $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
+                       if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
+                               $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
+                       else
+                               $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
+               }
 
-               foreach ($sizes as $size) {
-                       $resized = image_make_intermediate_size( $full_path_file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") );
+               $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
+
+               foreach ($sizes as $size => $size_data ) {
+                       $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
                        if ( $resized )
                                $metadata['sizes'][$size] = $resized;
                }
 
                // fetch additional metadata from exif/iptc
-               $image_meta = wp_read_image_metadata( $full_path_file );
-               if ($image_meta)
+               $image_meta = wp_read_image_metadata( $file );
+               if ( $image_meta )
                        $metadata['image_meta'] = $image_meta;
 
        }
 
-       return apply_filters( 'wp_generate_attachment_metadata', $metadata );
+       return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
 }
 
 /**
@@ -326,5 +341,3 @@ function file_is_displayable_image($path) {
 
        return apply_filters('file_is_displayable_image', $result, $path);
 }
-
-?>