Make WordPress Core


Ignore:
Timestamp:
12/12/2006 08:36:16 AM (20 years ago)
Author:
ryan
Message:

Move wp_generate_attachment_metadata() and friends to admin-functions.php and include admin-functions from xmlrpc.

File:
1 edited

Legend:

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

    r4631 r4643  
    11101110}
    11111111
    1112 function wp_generate_attachment_metadata( $attachment_id, $file ) {
    1113         $attachment = get_post( $attachment_id );
    1114 
    1115         $metadata = array();
    1116         if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) {
    1117                 $imagesize = getimagesize($file);
    1118                 $metadata['width'] = $imagesize['0'];
    1119                 $metadata['height'] = $imagesize['1'];
    1120                 list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']);
    1121                 $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
    1122                 $metadata['file'] = $file;
    1123 
    1124                 if ( $metadata['width'] * $metadata['height'] < 3 * 1024 * 1024 ) {
    1125                         if ( $metadata['width'] > 128 && $metadata['width'] >= $metadata['height'] * 4 / 3 )
    1126                                 $thumb = wp_create_thumbnail($file, 128);
    1127                         elseif ( $metadata['height'] > 96 )
    1128                                 $thumb = wp_create_thumbnail($file, 96);
    1129 
    1130                         if ( @file_exists($thumb) )
    1131                                 $metadata['thumb'] = basename($thumb);
    1132                 }
    1133         }
    1134         return apply_filters( 'wp_generate_attachment_metadata', $metadata );
    1135 }
    1136 
    1137 function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
    1138 
    1139                 // 1 = GIF, 2 = JPEG, 3 = PNG
    1140 
    1141         if ( file_exists( $file ) ) {
    1142                 $type = getimagesize( $file );
    1143 
    1144                 // if the associated function doesn't exist - then it's not
    1145                 // handle. duh. i hope.
    1146 
    1147                 if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
    1148                         $error = __( 'Filetype not supported. Thumbnail not created.' );
    1149                 }
    1150                 elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
    1151                         $error = __( 'Filetype not supported. Thumbnail not created.' );
    1152                 }
    1153                 elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
    1154                         $error = __( 'Filetype not supported. Thumbnail not created.' );
    1155                 } else {
    1156 
    1157                         // create the initial copy from the original file
    1158                         if ( $type[2] == 1 ) {
    1159                                 $image = imagecreatefromgif( $file );
    1160                         }
    1161                         elseif ( $type[2] == 2 ) {
    1162                                 $image = imagecreatefromjpeg( $file );
    1163                         }
    1164                         elseif ( $type[2] == 3 ) {
    1165                                 $image = imagecreatefrompng( $file );
    1166                         }
    1167 
    1168                         if ( function_exists( 'imageantialias' ))
    1169                                 imageantialias( $image, TRUE );
    1170 
    1171                         $image_attr = getimagesize( $file );
    1172 
    1173                         // figure out the longest side
    1174 
    1175                         if ( $image_attr[0] > $image_attr[1] ) {
    1176                                 $image_width = $image_attr[0];
    1177                                 $image_height = $image_attr[1];
    1178                                 $image_new_width = $max_side;
    1179 
    1180                                 $image_ratio = $image_width / $image_new_width;
    1181                                 $image_new_height = $image_height / $image_ratio;
    1182                                 //width is > height
    1183                         } else {
    1184                                 $image_width = $image_attr[0];
    1185                                 $image_height = $image_attr[1];
    1186                                 $image_new_height = $max_side;
    1187 
    1188                                 $image_ratio = $image_height / $image_new_height;
    1189                                 $image_new_width = $image_width / $image_ratio;
    1190                                 //height > width
    1191                         }
    1192 
    1193                         $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
    1194                         @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
    1195 
    1196                         // If no filters change the filename, we'll do a default transformation.
    1197                         if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) )
    1198                                 $thumb = preg_replace( '!(\.[^.]+)?$!', __( '.thumbnail' ).'$1', basename( $file ), 1 );
    1199 
    1200                         $thumbpath = str_replace( basename( $file ), $thumb, $file );
    1201 
    1202                         // move the thumbnail to it's final destination
    1203                         if ( $type[2] == 1 ) {
    1204                                 if (!imagegif( $thumbnail, $thumbpath ) ) {
    1205                                         $error = __( "Thumbnail path invalid" );
    1206                                 }
    1207                         }
    1208                         elseif ( $type[2] == 2 ) {
    1209                                 if (!imagejpeg( $thumbnail, $thumbpath ) ) {
    1210                                         $error = __( "Thumbnail path invalid" );
    1211                                 }
    1212                         }
    1213                         elseif ( $type[2] == 3 ) {
    1214                                 if (!imagepng( $thumbnail, $thumbpath ) ) {
    1215                                         $error = __( "Thumbnail path invalid" );
    1216                                 }
    1217                         }
    1218 
    1219                 }
    1220         } else {
    1221                 $error = __( 'File not found' );
    1222         }
    1223 
    1224         if (!empty ( $error ) ) {
    1225                 return $error;
    1226         } else {
    1227                 apply_filters( 'wp_create_thumbnail', $thumbpath );
    1228                 return $thumbpath;
    1229         }
    1230 }
    1231 
    12321112function wp_explain_nonce($action) {
    12331113        if ( $action !== -1 && preg_match('/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches) ) {
Note: See TracChangeset for help on using the changeset viewer.