サムネールタグの投稿
2008-03-27

WordPress 2.1〜2.3 でサムネールサイズをプラグインで変更する
以前、WPJ フォーラムに投稿したネタで、「デフォルトのサムネールサイズをプラグインで変更する」というのがありました。デフォルトは、「長辺側が128ピクセル」と小さめになっています。WordPress のコアファイルをいじって大きくする改造がよく見かけられますが、それだとアップグレードの度に修正が必要です。プラグインならば、改造のやり直しは不要です。
WPJ フォーラムの廃止が迫っているので、ソースコードをサルベージしておきましょう。オリジナルはわざわざクラス宣言していますが、それはやめて単純化してあります。また、ライセンスが不明でしたが、tai さんの指定通り GPL としておきます (パブリックドメインにしたいけど日本では困難)。なお、WordPress 2.0.x 以前では wp_thumbnail_max_side_length フックがないので、このプラグインは使えません。また、WordPress 2.5 からは画像アップロード時にサムネールサイズを指定できる、かつ、wp_thumbnail_max_side_length がないのでお役御免です。
<?php
/*
Plugin Name: Change Thumbnail Max Side Length
Plugin URI: http://www.yuriko.net/arc/2008/03/27d
Description: Change the max side length of thumbnails.
Author: IKEDA yuriko
Version: 0.80
Author URI: http://www.yuriko.net/cat/wordpress
*/
/* Copyright (c) 2007-2008 yuriko
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; version 2 of the License.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
define('MY_THUMBNAIL_MAX_SIDE_LENGTH', 160);
function change_thumb_max_length($length, $attachment_id, $file) {
return MY_THUMBNAIL_MAX_SIDE_LENGTH;
}
add_filter('wp_thumbnail_max_side_length', 'change_thumb_max_length', 10, 3);
?>
[追記 2009-01-23] この投稿に対するスパムコメントが多いため、当面コメント不可とさせて頂きます。

上に戻る