コメント |
@DIV
<?
ini_set( 'display_errors', "1" );
header('Content-Type: image/png');
//header('Content-Type: text/html');
if ( $_GET['img'] == '' ) {
$_GET['img'] = 'a.png';
}
if ( $_GET['c'] == '' ) {
$_GET['c'] = 'ffffff';
}
$r = hexdec( substr( $_GET['c'], 0, 2 ) );
$g = hexdec( substr( $_GET['c'], 2, 2 ) );
$b = hexdec( substr( $_GET['c'], 4, 2 ) );
$pi = pathinfo($_GET['img']);
$ext = strtolower($pi['extension']);
if ( $ext == 'png' ) {
$im = @imagecreatefrompng($_GET['img']);
}
if ( $ext == 'gif' ) {
$im = @imagecreatefromgif($_GET['img']);
}
if ( $ext == 'jpg' || $ext == 'jpeg' ) {
$im = @imagecreatefromjpeg($_GET['img']);
}
// 失敗
if(!$im) {
//空の画像
$im = imagecreatetruecolor(200, 200); // 200x200
$bgc = imagecolorallocate($im, 255, 255, 255); // 背景色(白)
$tc = imagecolorallocate($im, 0, 0, 0); // 文字色(黒)
imagefilledrectangle($im, 0, 0, 200, 200, $bgc); // 背景を塗る
// メッセージ
// (5,5) は座標
imagestring($im, 1, 5, 5, 'Error loading', $tc);
}
else {
$ww = imagesx( $im );
$hh = imagesy( $im );
//空の画像
$im_base = imagecreatetruecolor($ww, $hh); // 200x200
$bgc = imagecolorallocate($im_base, $r, $g, $b); // 背景色(白)
imagefilledrectangle($im_base, 0, 0, $ww, $hh, $bgc); // 背景を塗る
imagecopy($im_base, $im, 0, 0, 0, 0, $ww, $hh );
$im = $im_base;
}
/*
// 縮小は品質が悪いのでボツ
if ( $_GET['w'] != '' ) {
$nw = $_GET['w']+0;
$nh = $hh * ( $nw / $ww );
$thumb = imagecreatetruecolor( $nw, $nh );
imagecopyresized($thumb, $im, 0, 0, 0, 0, $nw, $nh, $ww, $hh);
$im = $thumb;
}
*/
// PNG イメージをブラウザに出力する
imagepng($im);
// 画像を破棄する
imagedestroy($im);
?>
@END |