SQLの窓

2015年02月14日


PHP による『超簡易掲示板』 / アプリケーションからの POST 検証用



デモページ

2015-02-14 : 更新
コメントを追加して、特殊な文字を無効化しました

2013/01/07 : 更新
Chrome での表示で、\n 埋め込まれているデータを <br /> に変換して、実際に改行して見えるようにしました。

Windows Phone(C#) から使うと、エミュレータ内では取得しにくい長い文字列を LOG 等の目的で出力可能です。

1) Google Chrome から実行すると、『掲示板として動作します』
※ F12 の開発者ツールでデバイスモードにしてから、リセットして UA に適当な文字を入力して再表示すると JSON 表示されます( iPad 等でもいいですが、それではテキスト選択ができません )







2) それ以外のブラウザからだと、表示されるのは JSON です
<?php
// **************************************
// ブラウザの判定をしています
// ( $_SERVER['HTTP_USER_AGENT'] )
// **************************************
$AGENT = "";
if ( strpos( $_SERVER['HTTP_USER_AGENT'], "Chrome") !== false ) {
	$AGENT = "Chrome";
}

// **************************************
// ブラウザが Google Chrome の場合のみ
// 通常の HTML として出力します
// ※ キャラクタセットは UTF-8 です
// **************************************
if ( $AGENT == "Chrome" ) {
	header( "Content-Type: text/html; Charset=utf-8" );
}
else {
	header( "Content-Type: text/plain; Charset=utf-8" );
}

// **************************************
// キャッシュを無効にするヘッダです
// **************************************
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

$log_text = @file_get_contents("./text.log");
// **************************************
// 書き込み処理です
// **************************************
if ( $_POST['send'] != "" && $_POST['text'] != "" ) {
	// **************************************
	// 本文中の改行コードを "\n" という
	// 文字列に変換しています
	// **************************************
	$log_wk = str_replace("\r\n","\\n",$_POST['text']);
	$log_wk = str_replace("\n","\\n", $log_wk );
	$log_wk = str_replace("\r","\\n", $log_wk );

	// **************************************
	// 特殊な文字を無効化します
	// **************************************
	$log_wk = str_replace("&","&amp;",$log_wk);
	$log_wk = str_replace("<","&lt;",$log_wk);
	$log_wk = str_replace(">","&gt;",$log_wk);
	// シングルクォート
	$log_wk = str_replace("'","&#39;",$log_wk);
	// ダブルクォート
	$log_wk = str_replace("\"","&#34;",$log_wk);

	// **************************************
	// 前回データとの境界に改行コードを
	// 設定しています
	// **************************************
	$log_text = $log_wk . "\n" . $log_text;

	file_put_contents("./text.log", $log_text );
	if ( $AGENT == "Chrome" ) {
		// GET メソッドで再表示します
		header( "Location: {$_SERVER["PHP_SELF"]}" );
		exit();
	}
}

// **************************************
// 環境によって必要ありませんが、
// エラー時の設定です
// **************************************
error_reporting(E_ALL ^ E_NOTICE);
ini_set( "display_errors", "1" );

// **************************************
// Chrome 以外では JSON 文字列で返します
// ※ text.log にデータが保存されています
// **************************************
if ( $AGENT != "Chrome" ) {
?>
{
	"item" : [ 
<?php
	$json_data = @file( "./text.log" );

	$cnt = count($json_data);
	for( $i = 0; $i < $cnt; $i++ ) {
		if ( $i != 0 ) {
			print "\t\t,{ \"text\": \"" . chop($json_data[$i]) . "\" }\n";
		}
		else {
			print "\t\t{ \"text\": \"" . chop($json_data[$i]) . "\" }\n";
		}
	}
?>

	]
}
<?
}
else {
	// **************************************
	// 記事の境界を hr 要素で表現します
	// **************************************
	$log_text = str_replace("\n", "<hr style='color:#c0c0c0;'>\n", $log_text );

	// **************************************
	// 本文の改行は br 要素で表現します
	// **************************************
	$log_text = str_replace("\\n", "<br>\n", $log_text );
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=1280,initial-scale=1.0">
</head>

<body>

<form method="POST">
<textarea name="text" style="width:400px;height:100px;"></textarea>
<br>
<input type="submit" name="send" value="送信">
</form>

<?= $log_text ?>
</body>
</html>
<? } ?>

関連する記事

コマンドプロンプトから Windows PHP を使って POST 投稿する

関連するオンラインツール

JSON チェック( JSONLint / The JSON Validator )



posted by lightbox at 2015-02-14 11:12 | PHP + WEBアプリ | このブログの読者になる | 更新情報をチェックする

2014年10月31日


PHP : 既存 GD 関連ライブラリで、背景をグラデーション(2)






開始  終了 
タイプ 
ステップ  


ライブラリ関連のソースコードは、『PHP : 既存 GD 関連ライブラリで、背景をグラデーション』を参照して下さい。グラデーションクラスと、GD 基本クラスを紹介しています。

それらのクラスを使用して実行していますが、PHP 自体を画像としてブラウザに返すコードなので、ここでの実行は、IMG 要素の SRC 属性に QueryString を引き渡して随時実行しています。

※ 今回は、コードの中に他のサイトから実行した場合に以下の画像が表示されるようにするコードを付加しています。

( ▲ クリックすると、フリーフォントで簡単ロゴ作成に移動します )

example_02.php(UTF-8N)
<?php
// ***********************************************
//
//  プログラム名 : グラデーションサンプル(2)
//  作   成   者 : lightbox
//  作   成   日 : 2014/10/31
//
//  概要 : 
//  背景画像としてのグラデーション
//
// ***********************************************
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

require_once('gd_lightbox.php');
require_once('gradient.php');

// ステップの範囲を限定
if ( $_GET['step']+0 > 20 ) {
	$_GET['step'] = 20;
}
if ( $_GET['step']+0 < 0 ) {
	$_GET['step'] = 0;
}
if ( $_GET['type'] == '' ) {
	$_GET['type'] = "horizontal";
}
if ( $_GET['sc'] == '' ) {
	$_GET['sc'] = "#000000";
}
if ( $_GET['ec'] == '' ) {
	$_GET['ec'] = "#ffffff";
}

// グラデーションキャンバスの作成
$gradient = new gd_gradient_fill(400,200,$_GET['type'],$_GET['sc'],$_GET['ec'],$_GET['step']+0);
// サイズ 400x200
$image = $gradient->image;

// GD インスタンス作成
$gd = new GD();

// PNG として設定
$gd->type = "PNG";
// グラデーションを設定
$gd->im = $image;

$site = false;
$target_sites = array("http://toolbox.winofsql.jp/","http://logicalerror.seesaa.net/");
foreach( $target_sites as $target ) {
	$len = strlen( $target );
	$ref = substr( $_SERVER['HTTP_REFERER'], 0, $len );
	if ( $target == $ref ) {
		$site = true;
		break;
	}
}

if ( $site ) {
	// ブラウザへ出力
	$gd->Response();
}
else {
	// ブラウザへ出力
	$gd->LoadPng("site_warning.png");
	$gd->Response();
}
?>


▼ このブログでの実装コード
<script>
if ( !window.jQuery ) {
	document.write("<"+"script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></"+"script>");
}
if ( window[window.location.hostname+'.loadModcoder'] !== true ) {
	window[window.location.hostname+'.loadModcoder'] = true;
	document.write("<"+"script src="http://homepage2.nifty.com/lightbox/modcoder_excolor/jquery.modcoder.excolor.js"></"+"script>");
}
</script>
<script type="text/javascript">
$(function(){
	$(".color_field").modcoder_excolor();
});

function set_gradient() {
	var src = "http://toolbox.winofsql.jp/gradient/example_02.php?step=" + $("#step").val();
	src += "&sc=" + encodeURIComponent($("#sc").val());
	src += "&ec=" + encodeURIComponent($("#ec").val());
	src += "&type=" + $("#gtype").val();
	$("#gradient").prop("src",src);
}
</script>

<style type="text/css">
.color_field {
	width: 80px;
}
</style>
<pre class=w6>
開始 <input id="sc" class="color_field" type="text" readonly value="#000000"> 終了 <input id="ec" class="color_field" type="text" readonly value="#ffffff">
タイプ <select id="gtype">
<option value="horizontal">horizontal</option>
<option value="vertical">vertical</option>
<option value="ellipse">ellipse</option>
<option value="ellipse2">ellipse2</option>
<option value="circle">circle</option>
<option value="circle2">circle2</option>
<option value="square">square</option>
<option value="diamond">diamond</option>
</select>
ステップ <input id="step" type="number" max="20" min="0" value="0"> <input type="button" value="グラデーション" onclick='set_gradient()'>
<img id="gradient" src="https://lh3.googleusercontent.com/-vhWb-RDtIR8/VFNVjqUJ8mI/AAAAAAAAXVU/7wyCb2JipJM/s400/gradient.png" style='border:solid 1px #000000;' onclick='set_gradient()'>
IE がまだ type="color" に対応していないので、カラーピッカーは jQuery のプラグインを使用しています


posted by lightbox at 2014-10-31 21:14 | PHP + WEBアプリ | このブログの読者になる | 更新情報をチェックする

PHP : 既存 GD 関連ライブラリで、背景をグラデーション

画像そのものを php で作成しています。クリックすると、img 要素の中の src の URLに渡す step パラメータが変化します。

▼ クリックするとグラデーションをテストできます。
ステップ  

( せっかくなので、step の入力は HTML5 の type="number" を使用してます / max="20" )

この間作成した、GD を使用した画像の縮小ライブラリと、『PHP and GD : Emulate Gradient Fill』からダウンロードできるグラデーション用ライブラリを使用して GD の背景としてグラデーションを設置するサンプルです。

Emulate Gradient Fill は、そのままでは使え無いので、74行目をコメントにする必要があります。また、テストしやすいようにコンストラクタの引数に全てデフォルトを設定しています。

※ このライブラリは、英語しか使われていないので、そのままで結構ですが、画像の縮小ライブラリと実行サンプルは、UTF-8N で保存しています。

gd_gradient_fill
<?php
/*
Script Name: GD Gradient Fill
Script URI: http://planetozh.com/blog/my-projects/images-php-gd-gradient-fill/
Description: Creates a gradient fill of any shape (rectangle, ellipse, vertical, horizontal, diamond)
Author: Ozh
Version: 1.1
Author URI: http://planetozh.com/
*/

/* Release history :
 * 1.1
 *		- changed : more nicely packaged as a class
 *		- fixed : not displaying proper gradient colors with image dimension greater than 255 (because of a limitation in imagecolorallocate)
 *		- added : optional parameter 'step', more options for 'direction'
 * 1.0
 *		- initial release
 */

/* Usage :
 *
 * require_once('/path/to/gd-gradient-fill.php');
 * $image = new gd_gradient_fill($width,$height,$direction,$startcolor,$endcolor,$step);
 *
 * Parameters :
 *		- width and height : integers, dimesions of your image.
 *		- direction : string, shape of the gradient.
 *		  Can be : vertical, horizontal, rectangle (or square), ellipse, ellipse2, circle, circle2, diamond.
 *		- startcolor : string, start color in 3 or 6 digits hexadecimal.
 *		- endcolor : string, end color in 3 or 6 digits hexadecimal.
 *		- step : integer, optional, default to 0. Step that breaks the smooth blending effect.
 * Returns a resource identifier.
 *
 * Examples :
 *
 * 1.
 * require_once('/home/ozh/www/includes/gd-gradient-fill.php');
 * $image = new gd_gradient_fill(200,200,'horizontal','#fff','#f00');
 *
 * 2.
 * require_once('c:/iis/inet/include/gd-gradient-fill.php');
 * $myimg = new gd_gradient_fill(80,20,'diamond','#ff0010','#303060');
 *
 */


// Test it :
// $image = new gd_gradient_fill(400,200,'ellipse','#f00','#000',0);

class gd_gradient_fill {
	
	// Constructor. Creates, fills and returns an image
	function gd_gradient_fill($w=400,$h=200,$d="horizontal",$s="#000000",$e="#FFFFFF",$step=0) {
		$this->width = $w;
		$this->height = $h;
		$this->direction = $d;
		$this->startcolor = $s;
		$this->endcolor = $e;
		$this->step = intval(abs($step));

		// Attempt to create a blank image in true colors, or a new palette based image if this fails
		if (function_exists('imagecreatetruecolor')) {
			$this->image = imagecreatetruecolor($this->width,$this->height);
		} elseif (function_exists('imagecreate')) {
			$this->image = imagecreate($this->width,$this->height);
		} else {
			die('Unable to create an image');
		}
		
		// Fill it
		$this->fill($this->image,$this->direction,$this->startcolor,$this->endcolor);
		
		// Show it		
//		$this->display($this->image);
		
		// Return it
		return $this->image;
	}
	
	
	// Displays the image with a portable function that works with any file type
	// depending on your server software configuration
	function display ($im) {
		if (function_exists("imagepng")) {
			header("Content-type: image/png");
			imagepng($im);
		}
		elseif (function_exists("imagegif")) {
			header("Content-type: image/gif");
			imagegif($im);
		}
		elseif (function_exists("imagejpeg")) {
			header("Content-type: image/jpeg");
			imagejpeg($im, "", 0.5);
		}
		elseif (function_exists("imagewbmp")) {
			header("Content-type: image/vnd.wap.wbmp");
			imagewbmp($im);
		} else {
			die("Doh ! No graphical functions on this server ?");
		}
		return true;
	}
	
	
	// The main function that draws the gradient
	function fill($im,$direction,$start,$end) {
		
		switch($direction) {
			case 'horizontal':
				$line_numbers = imagesx($im);
				$line_width = imagesy($im);
				list($r1,$g1,$b1) = $this->hex2rgb($start);
				list($r2,$g2,$b2) = $this->hex2rgb($end);
				break;
			case 'vertical':
				$line_numbers = imagesy($im);
				$line_width = imagesx($im);
				list($r1,$g1,$b1) = $this->hex2rgb($start);
				list($r2,$g2,$b2) = $this->hex2rgb($end);
				break;
			case 'ellipse':
				$width = imagesx($im);
				$height = imagesy($im);
				$rh=$height>$width?1:$width/$height;
				$rw=$width>$height?1:$height/$width;
				$line_numbers = min($width,$height);
				$center_x = $width/2;
				$center_y = $height/2;
				list($r1,$g1,$b1) = $this->hex2rgb($end);
				list($r2,$g2,$b2) = $this->hex2rgb($start);
				imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 ));
				break;
			case 'ellipse2':
				$width = imagesx($im);
				$height = imagesy($im);
				$rh=$height>$width?1:$width/$height;
				$rw=$width>$height?1:$height/$width;
				$line_numbers = sqrt(pow($width,2)+pow($height,2));
				$center_x = $width/2;
				$center_y = $height/2;
				list($r1,$g1,$b1) = $this->hex2rgb($end);
				list($r2,$g2,$b2) = $this->hex2rgb($start);
				break;
			case 'circle':
				$width = imagesx($im);
				$height = imagesy($im);
				$line_numbers = sqrt(pow($width,2)+pow($height,2));
				$center_x = $width/2;
				$center_y = $height/2;
				$rh = $rw = 1;
				list($r1,$g1,$b1) = $this->hex2rgb($end);
				list($r2,$g2,$b2) = $this->hex2rgb($start);
				break;
			case 'circle2':
				$width = imagesx($im);
				$height = imagesy($im);
				$line_numbers = min($width,$height);
				$center_x = $width/2;
				$center_y = $height/2;
				$rh = $rw = 1;
				list($r1,$g1,$b1) = $this->hex2rgb($end);
				list($r2,$g2,$b2) = $this->hex2rgb($start);
				imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 ));
				break;
			case 'square':
			case 'rectangle':
				$width = imagesx($im);
				$height = imagesy($im);
				$line_numbers = max($width,$height)/2;
				list($r1,$g1,$b1) = $this->hex2rgb($end);
				list($r2,$g2,$b2) = $this->hex2rgb($start);
				break;
			case 'diamond':
				list($r1,$g1,$b1) = $this->hex2rgb($end);
				list($r2,$g2,$b2) = $this->hex2rgb($start);
				$width = imagesx($im);
				$height = imagesy($im);
				$rh=$height>$width?1:$width/$height;
				$rw=$width>$height?1:$height/$width;
				$line_numbers = min($width,$height);
				break;
			default:
		}
		
		for ( $i = 0; $i < $line_numbers; $i=$i+1+$this->step ) {
			// old values :
			$old_r=$r;
			$old_g=$g;
			$old_b=$b;
			// new values :
			$r = ( $r2 - $r1 != 0 ) ? intval( $r1 + ( $r2 - $r1 ) * ( $i / $line_numbers ) ): $r1;
			$g = ( $g2 - $g1 != 0 ) ? intval( $g1 + ( $g2 - $g1 ) * ( $i / $line_numbers ) ): $g1;
			$b = ( $b2 - $b1 != 0 ) ? intval( $b1 + ( $b2 - $b1 ) * ( $i / $line_numbers ) ): $b1;
			// if new values are really new ones, allocate a new color, otherwise reuse previous color.
			// There's a "feature" in imagecolorallocate that makes this function
			// always returns '-1' after 255 colors have been allocated in an image that was created with
			// imagecreate (everything works fine with imagecreatetruecolor)
			if ( "$old_r,$old_g,$old_b" != "$r,$g,$b") 
				$fill = imagecolorallocate( $im, $r, $g, $b );
			switch($direction) {
				case 'vertical':
					imagefilledrectangle($im, 0, $i, $line_width, $i+$this->step, $fill);
					break;
				case 'horizontal':
					imagefilledrectangle( $im, $i, 0, $i+$this->step, $line_width, $fill );
					break;
				case 'ellipse':
				case 'ellipse2':
				case 'circle':
				case 'circle2':
					imagefilledellipse ($im,$center_x, $center_y, ($line_numbers-$i)*$rh, ($line_numbers-$i)*$rw,$fill);
					break;
				case 'square':
				case 'rectangle':
					imagefilledrectangle ($im,$i*$width/$height,$i*$height/$width,$width-($i*$width/$height), $height-($i*$height/$width),$fill);
					break;
				case 'diamond':
					imagefilledpolygon($im, array (
						$width/2, $i*$rw-0.5*$height,
						$i*$rh-0.5*$width, $height/2,
						$width/2,1.5*$height-$i*$rw,
						1.5*$width-$i*$rh, $height/2 ), 4, $fill);
					break;
				default:	
			}		
		}
	}
	
	// #ff00ff -> array(255,0,255) or #f0f -> array(255,0,255)
	function hex2rgb($color) {
		$color = str_replace('#','',$color);
		$s = strlen($color) / 3;
		$rgb[]=hexdec(str_repeat(substr($color,0,$s),2/$s));
		$rgb[]=hexdec(str_repeat(substr($color,$s,$s),2/$s));
		$rgb[]=hexdec(str_repeat(substr($color,2*$s,$s),2/$s));
		return $rgb;
	}
}
?>

今回のサンプルでは、step だけを変更できるようにしました。step は、デフォルトでは 0 を使用してなめらかなグラデーションになりますが、大きくする事によって、縦の縞模様の幅が広くなっていきます。( 特別なデザインで必要な場合以外使用する事は無いと思います )

example_01.php
<?php
// ***********************************************
//
//  プログラム名 : グラデーションサンプル(1)
//  作   成   者 : lightbox
//  作   成   日 : 2014/10/31
//
//  概要 : 
//  背景画像としてのグラデーション
//
// ***********************************************
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

require_once('gd_lightbox.php');
require_once('gradient.php');

// ステップの範囲を限定
if ( $_GET['step']+0 > 20 ) {
	$_GET['step'] = 20;
}
if ( $_GET['step']+0 < 0 ) {
	$_GET['step'] = 0;
}

// グラデーションキャンバスの作成
$gradient = new gd_gradient_fill(400,200,"horizontal","#000000","#FFFFFF",$_GET['step']+0);
// 1) 400x200
// 2) horizontal
// 3) 黒から白へ
$image = $gradient->image;

// GD インスタンス作成
$gd = new GD();

// PNG として設定
$gd->type = "PNG";
// グラデーションを設定
$gd->im = $image;
// PNGファイルとして出力
//$gd->SavePng("example_01.png");
// JPEGファイルとして出力( 第二引数を省略すると 75 )
//$gd->SavePng("example_01.jpg",90);

// ブラウザへ出力
$gd->Response();
?>

※ 画像として保存する処理をコメントにしています

gd_lightbox.php
<?php
# ***********************
# クラス
# ***********************
class GD {

	var $im;
	var $type;

# ***********************
# コンストラクタ
# ***********************
	function GD( ) {
	}

# ***********************
# キャンバス作成
# ***********************
	function CreateCanvas( $Width, $Height, $Type="PNG" ) {
		$this->type = $Type;
		$this->im = imagecreatetruecolor($Width, $Height);
	}

# ***********************
# PNG ロード
# ***********************
	function LoadPng( $Target ) {
		$this->type = "PNG";
		$this->im = ImageCreateFromPng($Target);
	}
 
# ***********************
# JPEG ロード
# ***********************
	function LoadJpeg( $Target ) {
		$this->type = "JPEG";
		$this->im = ImageCreateFromJpeg($Target);
	}

# ***********************
# 色リソース作成
# ***********************
	function CreateColor( $Red, $Green, $Blue ) {
		$ret = ImageColorAllocate (
			$this->im,
			$Red, $Green, $Blue );
		return $ret;
	}

# ***********************
# 線幅設定
# ***********************
	function SetLineWidth( $Width ) {
		ImageSetThickness( $this->im, $Width );
	}

# ***********************
# 直線の描画
# ***********************
	function Line( $x1, $y1, $x2, $y2, $Option ) {
		if ( is_array( $Option ) ) {
			ImageSetStyle( $this->im, $Option );
			ImageLine(
				$this->im, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED );
		}
		else {
			ImageLine(
				$this->im, $x1, $y1, $x2, $y2, $Option );
		}
	}

# ***********************
# 矩形の描画
# ***********************
	function Box( $x, $y, $w, $h, $Color, $fill=FALSE ) {
		if ( $fill ) {
			imageFilledRectAngle(
				$this->im, $x, $y, $x+$w, $y+$h, $Color );
		}
		else {
			ImageRectAngle(
				$this->im, $x, $y, $x+$w, $y+$h, $Color );
		}
	}

# ***********************
# 楕円の描画
# ***********************
	function Arc( $x, $y, $w, $h, $Color ) {
		ImageArc( $this->im, $x, $y, $w, $h, 0, 359, $Color );
	}

# ***********************
# ブラウザへ出力
# ***********************
	function Response( ) {
		switch( $this->type ) {
			case "PNG":
				header('Content-Type: image/png');
				ImagePng( $this->im );
				break;
			case "JPEG":
				header('Content-Type: image/jpeg');
				ImageJpeg( $this->im );
				break;
		}
	}

# ***********************
# PNG 保存
# ***********************
	function SavePng( $FilePath ) {
		ImagePng( $this->im, $FilePath );
	}

# ***********************
# JPEG 保存
# ***********************
	function SaveJpeg( $FilePath, $Quality=75 ) {
		ImageJpeg( $this->im, $FilePath, $Quality );
	}

# ***********************
# 色リソース開放
# ***********************
	function DestroyColor( $Color ) {
		ImageColorDeallocate( $this->im, $Color );
	}

# ***********************
# イメージの破棄
# ***********************
	function Destroy( ) {
		ImageDestroy ( $this->im );
	}

# ***********************
# 伸縮された新しいイメージの作成
# ***********************
	function Copy( &$New, $rate ) {
		$w = ImageSx( $this->im );
		$h = ImageSy( $this->im );
		$New = new GD();
		$New->im = ImageCreateTrueColor( $w * $rate, $h * $rate );
		$w2 = ImageSx( $New->im );
		$h2 = ImageSy( $New->im );
		ImageCopyResampled(
			$New->im,
			$this->im,
			0,0,0,0,
			$w2, $h2,
			$w, $h
		);
		$New->type = $this->type;
	}

	function CopyW( &$New, $w_new ) {
		$w = ImageSx( $this->im );
		$rate = $w_new / $w;
		$h = ImageSy( $this->im );
		$New = new GD();
		$New->im = ImageCreateTrueColor( $w_new, $h * $rate );
		$w2 = ImageSx( $New->im );
		$h2 = ImageSy( $New->im );
		ImageCopyResampled(
			$New->im,
			$this->im,
			0,0,0,0,
			$w2, $h2,
			$w, $h
		);
		$New->type = $this->type;
	}

	function CopyH( &$New, $h_new ) {
		$w = ImageSx( $this->im );
		$h = ImageSy( $this->im );
		$rate = $h_new / $h;
		$New = new GD();
		$New->im = ImageCreateTrueColor( $w * $rate, $h_new );
		$w2 = ImageSx( $New->im );
		$h2 = ImageSy( $New->im );
		ImageCopyResampled(
			$New->im,
			$this->im,
			0,0,0,0,
			$w2, $h2,
			$w, $h
		);
		$New->type = $this->type;
	}

	function CopyWH( &$New, $w_new, $h_new ) {
		$w = ImageSx( $this->im );
		$h = ImageSy( $this->im );
		$New = new GD();
		$New->im = ImageCreateTrueColor( $w_new, $h_new );
		$w2 = ImageSx( $New->im );
		$h2 = ImageSy( $New->im );
		ImageCopyResampled(
			$New->im,
			$this->im,
			0,0,0,0,
			$w2, $h2,
			$w, $h
		);
		$New->type = $this->type;
	}
}
?>




posted by lightbox at 2014-10-31 19:24 | PHP + WEBアプリ | このブログの読者になる | 更新情報をチェックする

2014年09月27日


PHP : 入力値のデバッグ

ソースコードの最下部に追加すれば良いと思います。
<?php
print "<pre>";
print_r($_GET);
print_r($_POST);
print "</pre>";
?>

デバッグする文字列に HTML が含まれている場合は、以下のようにするといいと思います。
<?php
foreach( $_POST as $key => $value ) {
	$_mypost[$key] = htmlentities( $value, ENT_NOQUOTES, "utf-8" );
}
print "<pre>";
print_r($_mypost);
print "</pre>";
?>







タグ:PHP
posted by lightbox at 2014-09-27 16:20 | PHP + WEBアプリ | このブログの読者になる | 更新情報をチェックする

2011年06月30日


PHP : ImageMagick : 背景が透過する画像を作成

▼ クリック


色指定で 'none' を指定してみて下さい。ネタ元は、PHP マニュアルの テキスト描画ページの投稿データです





posted by lightbox at 2011-06-30 23:59 | PHP + WEBアプリ | このブログの読者になる | 更新情報をチェックする

2011年06月26日


PHP雛型(2会話DB更新処理) : MySQL、XMLHttpRequest、XML、JSON、Canvas





位置指定は、全て position:absolute です
  ( プレースホルダは、position:relative )

データ参照に XMLHttpRequest を使用しています

main.php の data_format 変数に "xml" をセットすると、xml で呼び出します

xml の Content-Type は application/xml です
  ( デバッグ時はブラウザで直接確認します )

json の Content-Type は text/plain です
  ( デバッグ時にブラウザで直接確認する為です )

mysql のデータは mysql_fetch_array で取り出しています

入力エリアの枠は canvas を使用しています

更新は form で IFRAME に対して送信しています
  ( IFRAME 内に書き出された JavaScript で元の画面操作を行います )



posted by lightbox at 2011-06-26 13:01 | PHP + WEBアプリ | このブログの読者になる | 更新情報をチェックする
Seesaa の各ページの表示について
Seesaa の 記事がたまに全く表示されない場合があります。その場合は、設定> 詳細設定> ブログ設定 で 最新の情報に更新の『実行ボタン』で記事やアーカイブが最新にビルドされます。

Seesaa のページで、アーカイブとタグページは要注意です。タグページはコンテンツが全く無い状態になりますし、アーカイブページも歯抜けページはコンテンツが存在しないのにページが表示されてしまいます。

また、カテゴリページもそういう意味では完全ではありません。『カテゴリID-番号』というフォーマットで表示されるページですが、実際存在するより大きな番号でも表示されてしまいます。

※ インデックスページのみ、実際の記事数を超えたページを指定しても最後のページが表示されるようです

対処としては、このようなヘルプ的な情報を固定でページの最後に表示するようにするといいでしょう。具体的には、メインの記事コンテンツの下に『自由形式』を追加し、アーカイブとカテゴリページでのみ表示するように設定し、コンテンツを用意するといいと思います。


※ エキスパートモードで表示しています

アーカイブとカテゴリページはこのように簡単に設定できますが、タグページは HTML 設定を直接変更して、以下の『タグページでのみ表示される内容』の記述方法で設定する必要があります

<% if:page_name eq 'archive' -%>
アーカイブページでのみ表示される内容
<% /if %>

<% if:page_name eq 'category' -%>
カテゴリページでのみ表示される内容
<% /if %>

<% if:page_name eq 'tag' -%>
タグページでのみ表示される内容
<% /if %>
この記述は、以下の場所で使用します
container 終わり



フリーフォントで簡単ロゴ作成
フリーフォントでボタン素材作成
フリーフォントで吹き出し画像作成
フリーフォントではんこ画像作成
ほぼ自由に利用できるフリーフォント
フリーフォントの書体見本とサンプル
画像を大きく見る為のウインドウを開くボタンの作成

CSS ドロップシャドウの参考デモ
イラストAC
ぱくたそ
写真素材 足成
フリーフォント一覧
utf8 文字ツール
右サイド 終わり
base 終わり