PHPのGDライブラリを使用して画像のリサイズをする関数を作ってみました。縦横長いほうを基準に引数で指定した長さにリサイズします。
※違うソース載っけてました。これが正解です。
function image_resize($source, $length){
//元画像のサイズをゲット
list($o_width, $o_height) = getimagesize($source);
//縦長か横長かをチェック
if($o_width > $o_height){//横長の場合
$height = ($o_height / $o_width) * $length;
$width = $length;
}else{//縦長の場合
$width = ($o_width / $o_height) * $length;
$height = $length;
}
//元画像を読み込み
$source = imagecreatefromjpeg($source);
//リサイズ用の画像を作成
$new_image = imagecreatetruecolor($width, $height);
//元画像からリサイズしてコピー
imagecopyresampled($new_image,$source, 0, 0, 0, 0,
$width, $height, $o_width, $o_height);
//画像の表示
header('Content-Type: image/jpeg');
imagejpeg($new_image,NULL,100);
imagedestroy($new_image);
}
image_resize("画像へのパス", リサイズ後のサイズ);
