今回追記したコードで新しくヘッダー画像を登録しようとするとこちらもリサイズされるエラー報告を頂きました。
お手数ですが、ヘッダー登録の際は一度functions.phpの下記に該当する箇所を削除して下さい。
登録を終えたら再度、追記頂ければと思います。
※ヘッダー登録済みのサイトは無視して下さい。
※直接FTPでimgagesフォルダ内の「stinger2.png」(stinger3の場合は「stinger3.png」)を差し替えて頂いてもOKです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/* Name : Resize an image at upload * Version: 1.0.0 * Author : Otokuni Consulting Co.,Ltd. * Author URI: http://www.oto-con.com/ * License: GPLv2 or later * Description : This function is useful when the user often upload very large size image. */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ function otocon_resize_at_upload( $file ) { // $file contains file, url, type // array( 'file' => 'path to the image', 'url' => 'url of the image', 'type' => 'mime type' ) // resize only if the mime type is image if ( $file['type'] == 'image/jpeg' OR $file['type'] == 'image/gif' OR $file['type'] == 'image/png') { // set width and height $w = intval(get_option( 'large_size_w' ) ); // get large size width $h = intval(get_option( 'large_size_h' ) ); // get large size height // get the uploaded image $image = wp_get_image_editor( $file['file'] ); // if no error if ( ! is_wp_error( $image ) ){ // get image width and height $size = getimagesize( $file['file'] ); // $size[0] = width, $size[1] = height if ( $size[0] > $w || $size[1] > $h ){ // if the width or height is larger than the large-size $image->resize( $w, $h, false ); // resize the image $final_image = $image->save( $file['file'] ); // save the resized image } } } // if mime type return $file; } add_action( 'wp_handle_upload', 'otocon_resize_at_upload' ); |