SQLの窓 イラストAC フリー素材

2014年10月15日

PHP + GD : 四角形への DropShadow



グラデーション方法のサンプル

how to create thumbnail + shadow by this script
/* offset of drop shadow from top left */
define ( "DS_OFFSET" , 5 );
 
/* number of steps from black to background color /*
define("DS_STEPS", 10);
 
/* distance between steps */
define ( "DS_SPREAD" , 1 );
 
/* define the background color */
$background = array( "r" => 255 , "g" =>  255 , "b" =>  255 );

// 元のサイズに対して、影のサイズを含めた新しい幅と高さを決定します
$width = $o_width + DS_OFFSET ;
$height = $o_height + DS_OFFSET ;
$image = imagecreatetruecolor ( $width , $height );
 
/* determine the offset between colors */
$step_offset = array( "r" =>  ( $background [ "r" ] / DS_STEPS ), "g" =>  ( $background [ "g" ] / DS_STEPS ), "b" =>  ( $background [ "b" ] / DS_STEPS ));
 
/* calculate and allocate the needed colors */
$current_color = $background ;
for ( $i = 0 ; $i <= DS_STEPS ; $i ++) {
	$colors [ $i ] = imagecolorallocate ( $image , round ( $current_color [ "r" ]), round ( $current_color [ "g" ]), round ( $current_color [ "b" ]));
 
	$current_color [ "r" ] -= $step_offset [ "r" ];
	$current_color [ "g" ] -= $step_offset [ "g" ];
	$current_color [ "b" ] -= $step_offset [ "b" ];
}
 
// 一番外側の四角
imagefilledrectangle ( $image , 0 , 0 , $width , $height , $colors [ 0 ]);
 
// だんだん小さく、色を濃く 
for ( $i = 0 ; $i < count ( $colors ); $i ++) {
	imagefilledrectangle ( $image , DS_OFFSET , DS_OFFSET , $width , $height , $colors [ $i ]);
	$width -= DS_SPREAD ;
	$height -= DS_SPREAD ;
}
ボックスをすこしづづ小さく薄く描画して、最終的には、imageconvolution でガウス分布のぼかしを実行しています( ガウス分布のぼかしは、マニュアルのサンプルにあります )
<?php
$image = imagecreatetruecolor(180,40);

imagestring($image, 5, 10, 8, 'Gaussian Blur Text', 0x00ff00);
$gaussian = array(
	array(1.0, 2.0, 1.0),
	array(2.0, 4.0, 2.0),
	array(1.0, 2.0, 1.0)
);
imageconvolution($image, $gaussian, 16, 0);




タグ:gd
【PHPの最新記事】
posted by at 2014-10-15 23:20 | PHP | このブログの読者になる | 更新情報をチェックする