我是wordpress的新手,我在上传过程中如何处理调整大小或裁剪图像方面存在问题。
我的自定义wordpress插件已经有了这个代码:
function my_handle_attachment($file_handler,$post_id,$set_thu=false) {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $post_id );
if ( is_numeric( $attach_id ) ) {
update_post_meta( $post_id, '_my_file_upload', $attach_id );
}
return $attach_id;
}
if ( $_FILES ) {
$files = $_FILES["img"];
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
$_FILES = array ("my_file_upload" => $file);
foreach ($_FILES as $file => $array) {
$newupload = my_handle_attachment($file,$pid);
// newly uploaded files
}
}
}
}
好吧,我尝试了add_image_size( 'mysize', 300, 300, true );
,但我想要调整原始图片的大小。
我的问题是,在上传过程中,图片会调整大小或裁剪为300X300。有可能吗?
答案 0 :(得分:-2)
为什么不在照片编辑应用程序中裁剪所需图像,然后上传它。