Make WordPress Core


Ignore:
Timestamp:
12/07/2006 10:42:22 PM (18 years ago)
Author:
ryan
Message:

Create attachment metadata for xmlrpc uploads. Props mdawaffe. fixes #3452

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r4612 r4628  
    852852    } else {
    853853        return false;
    854     }
    855 }
    856 
    857 function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
    858 
    859         // 1 = GIF, 2 = JPEG, 3 = PNG
    860 
    861     if ( file_exists( $file ) ) {
    862         $type = getimagesize( $file );
    863 
    864         // if the associated function doesn't exist - then it's not
    865         // handle. duh. i hope.
    866 
    867         if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
    868             $error = __( 'Filetype not supported. Thumbnail not created.' );
    869         }
    870         elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
    871             $error = __( 'Filetype not supported. Thumbnail not created.' );
    872         }
    873         elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
    874             $error = __( 'Filetype not supported. Thumbnail not created.' );
    875         } else {
    876 
    877             // create the initial copy from the original file
    878             if ( $type[2] == 1 ) {
    879                 $image = imagecreatefromgif( $file );
    880             }
    881             elseif ( $type[2] == 2 ) {
    882                 $image = imagecreatefromjpeg( $file );
    883             }
    884             elseif ( $type[2] == 3 ) {
    885                 $image = imagecreatefrompng( $file );
    886             }
    887 
    888             if ( function_exists( 'imageantialias' ))
    889                 imageantialias( $image, TRUE );
    890 
    891             $image_attr = getimagesize( $file );
    892 
    893             // figure out the longest side
    894 
    895             if ( $image_attr[0] > $image_attr[1] ) {
    896                 $image_width = $image_attr[0];
    897                 $image_height = $image_attr[1];
    898                 $image_new_width = $max_side;
    899 
    900                 $image_ratio = $image_width / $image_new_width;
    901                 $image_new_height = $image_height / $image_ratio;
    902                 //width is > height
    903             } else {
    904                 $image_width = $image_attr[0];
    905                 $image_height = $image_attr[1];
    906                 $image_new_height = $max_side;
    907 
    908                 $image_ratio = $image_height / $image_new_height;
    909                 $image_new_width = $image_width / $image_ratio;
    910                 //height > width
    911             }
    912 
    913             $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
    914             @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
    915 
    916             // If no filters change the filename, we'll do a default transformation.
    917             if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) )
    918                 $thumb = preg_replace( '!(\.[^.]+)?$!', __( '.thumbnail' ).'$1', basename( $file ), 1 );
    919 
    920             $thumbpath = str_replace( basename( $file ), $thumb, $file );
    921 
    922             // move the thumbnail to it's final destination
    923             if ( $type[2] == 1 ) {
    924                 if (!imagegif( $thumbnail, $thumbpath ) ) {
    925                     $error = __( "Thumbnail path invalid" );
    926                 }
    927             }
    928             elseif ( $type[2] == 2 ) {
    929                 if (!imagejpeg( $thumbnail, $thumbpath ) ) {
    930                     $error = __( "Thumbnail path invalid" );
    931                 }
    932             }
    933             elseif ( $type[2] == 3 ) {
    934                 if (!imagepng( $thumbnail, $thumbpath ) ) {
    935                     $error = __( "Thumbnail path invalid" );
    936                 }
    937             }
    938 
    939         }
    940     } else {
    941         $error = __( 'File not found' );
    942     }
    943 
    944     if (!empty ( $error ) ) {
    945         return $error;
    946     } else {
    947         apply_filters( 'wp_create_thumbnail', $thumbpath );
    948         return $thumbpath;
    949854    }
    950855}
Note: See TracChangeset for help on using the changeset viewer.