画像の拡大、縮小
imagecopyresampled
画像リソースを拡大、縮小
サンプル
<?php
// 200×200の画像リソースを作成
$im = imagecreate(200, 200);
// 白色を作成
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
// 黒色を作成
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$yellow = imagecolorallocate($im, 0xFF, 0xFF, 0x00);
// 短形を描画する
imagefilledrectangle($im, 50, 50, 150, 150, $yellow);
// フォントを指定
$font = "C:/Windows/Fonts/msgothic.ttc";
// テキストを描画
imagettftext($im, 14, 0, 20, 160, $black, $font, "ほげほげ");
imagettftext($im, 14, 330, 20, 20, $black, $font, "拡大テスト");
imagettftext($im, 14, 90, 120, 160, $black, $font, "1234567");
// 新しい画像サイズで作成
$new_width = 300;
$new_height = 300;
$im_new = imagecreatetruecolor($new_width, $new_height);
// リサイズ
imagecopyresampled($im_new, $im, 0, 0, 0, 0, $new_width, $new_height, 200, 200);
// 画像出力
header("Content-type: image/png");
ImagePNG($im_new);
?>
イメージ
サンプル
<?php
// 200×200の画像リソースを作成
$im = imagecreate(200, 200);
// 白色を作成
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
// 黒色を作成
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$yellow = imagecolorallocate($im, 0xFF, 0xFF, 0x00);
// 短形を描画する
imagefilledrectangle($im, 50, 50, 150, 150, $yellow);
// フォントを指定
$font = "C:/Windows/Fonts/msgothic.ttc";
// テキストを描画
imagettftext($im, 14, 0, 20, 160, $black, $font, "ほげほげ");
imagettftext($im, 14, 330, 20, 20, $black, $font, "縮小テスト");
imagettftext($im, 14, 90, 120, 160, $black, $font, "1234567");
// 新しい画像サイズで作成
$new_width = 90;
$new_height = 90;
$im_new = imagecreatetruecolor($new_width, $new_height);
// リサイズ
imagecopyresampled($im_new, $im, 0, 0, 0, 0, $new_width, $new_height, 200, 200);
// 画像出力
header("Content-type: image/png");
ImagePNG($im_new);
?>
イメージ
最終更新:2012年08月18日 22:30