调整大小已经完成,以创建大/中/拇指大小,但您面临的问题是图像太大,无法调整大小,这可能是因为内存不足或时间不足。
因此,调整大小不是一个选项,如果不是,你就不会有问题。相反,请尝试限制图像,这样,如果发生20MB的上载,它将被拒绝,并显示一条消息,指示需要缩小大小。
基于图像面积/百万像素的限制:
<?php
/**
* Plugin Name: Deny Giant Image Uploads
* Description: Prevents Uploads of images greater than 3.2MP
*/
function tomjn_deny_giant_images($file){
$type = explode(\'/\',$file[\'type\']);
if($type[0] == \'image\'){
list( $width, $height, $imagetype, $hwstring, $mime, $rgb_r_cmyk, $bit ) = getimagesize( $file[\'tmp_name\'] );
if($width * $height > 3200728){ // I added 100,000 as sometimes there are more rows/columns than visible pixels depending on the format
$file[\'error\'] = \'This image is too large, resize it prior to uploading, ideally below 3.2MP or 2048x1536\';
}
}
return $file;
}
add_filter(\'wp_handle_upload_prefilter\',\'tomjn_deny_giant_images\');
基于宽度或高度的限制:
https://wordpress.stackexchange.com/posts/67110/revisions
<?php
/** Plugin Name: (#67107) »kaiser« Restrict file upload */
function wpse67107_restrict_upload( $file )
{
$file_data = getimagesize( $file );
// Handle cases where we can\'t get any info:
if ( ! $file_data )
return $file;
list( $width, $height, $type, $hwstring, $mime, $rgb_r_cmyk, $bit ) = $file_data;
// Add conditions when to abort
if ( $width > 2048 )
$file[\'error\'] = \'Error statement\';
return $file;
}
add_filter( \'wp_handle_upload_prefilter\', \'wpse67107_restrict_upload\' );
按面积限制将允许调整大小的高/薄或宽/短图像,按尺寸限制可能更容易解释