php imagecopyresized实例
描述
布尔imagecopyresized($ dst_image,$ src_image,$ dst_x,$ dst_y,$ src_x,$
src_y,$ dst_w,$ dst_h,$ src_w,$ src_h)
imagecopyresized()拷贝一个长方形的部分图像到另一个图像。 dst_image的目标图
像,src_image是源图像的标识符。
换句话说,imagecopyresized()将于src_w的宽度和高度src_h src_image的位置
(src_x,src_y),并将其放置在dst_w的宽度和高度dst_h dst_image矩形区域,它是
在位置的矩形区域(dst_x,dst_y)。
如果源和目标坐标,宽度和高度不同,适当的伸展或收缩的图像片段将进行。坐标是指
在左上角。该功能可用于复制的图像在同一地区(如dst_image是相同的src_image),
但如果区域重叠的结果将不可预测。
参数说明:
dst_im
目标图像链接的资源。
src_im
源图像链接的资源。
dst_x
X坐标的目的地。
dst_y
y坐标目的地。
src_x
X坐标的源点。
src_y
y坐标源点。
dst_w
目的地宽度。
dst_h
目标高度。
src_w
源宽度。
src_h
源高度。
来看看imagecopyresized函数实例
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width,
$height);
// Output
imagejpeg($thumb);
?>
php imagecreatetruecolor创建高清图片函数
imagecreatetruecolor()返回一个图像标识符代表指定大小的黑色形象。
根据你的PHP和GD版本中函数定义与否。对于PHP 4.0.6通过4.1.x这个函数总是存在的
,如果广东模块加载,但它要求GD2的情况下被安装了PHP将发出一个致命错误并退出。
用PHP 4.2.x版这种行为是不同的人发出警告,而不是一个错误。其他版本只定义此功
能,
看看实例
<?php
header ('Content-type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>
我提出这方面合作 - 结合一些例子,然后动态生成的文本。但是,与此设置,我能得
到透明背景的工作也。
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
// The text to draw
$text = $_GET['text'];
// Replace path by your own font path
$font = 'catriel regular.ttf';
// Add some shadow to the text
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);
// Add the text
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
php imagecolorallocatealpha 创建透明图片实例
imagecolorallocatealpha(resource $image , int $red , int $green , int $blue
, int $alpha )
imagecolorallocatealpha()的行为相同imagecolorallocate()同阿尔法增加透明
度参数。
$image
图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。
$red
红色分量的价值。
$green
价值的绿色成分。
$blue
蓝色成分的价值。
$alpha
一个介于0和127的价值。 0表示完全不透明,而127表示完全透明。
来看个imagecolorallocatealpha实例教程
<?php
$size = 300;
$image=imagecreatetruecolor($size, $size);
// something to get a white background with black border
$back = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back);
imagerectangle($image, 0, 0, $size - 1, $size - 1, $border);
$yellow_x = 100;
$yellow_y = 75;
$red_x = 120;
$red_y = 165;
$blue_x = 187;
$blue_y = 125;
$radius = 150;
// allocate colors with alpha values
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
// drawing 3 overlapped circle
imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red);
imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue);
// don't forget to output a correct header!
header('Content-type: image/png');
// and finally, output the result
imagepng($image);
imagedestroy($image);
?>
php htmlspecialchars
在开发程序时经常会碰客户或网友输入html 进行注入操作,php提供一专业的函数来处理这种情况的发生,htmlspecialchars函。
htmlspecialchars(string,int quote_style,string charset);
它可以把<br>转换成html编码,好了下面我们来看一个简单的实例吧。
function PostGet($str,$post=0)
{
empty($str)?die('提供参数'.$str.'错误!'):'';
if( $post )
{
return addslashes(htmlspecialchars($_POST[$str]));
}
else
{
return addslashes(htmlspecialchars($_GET[$str]))
}
}
本站原创转载注明www.111cn.net
ob_start()是开启output buffering,也就是缓冲输入内容
ob_gzhandle使用gzip处理内容,作为ob_start的参数,表示当输入缓冲内容时使用的回调函数,你也可以自己定义回调函数
例如手册中的例子:
[php]
<?php
function callback($buffer)
{
// replace all the apples with oranges
return (str_replace("apples", "oranges", $buffer));
}
ob_start("callback");
?>
<html>
<body>
<p>It's like comparing apples to oranges.</p>
</body>
</html>
<?php
ob_end_flush();
?>
[/php]
输出时,内容中的apples会变成oranges,你可以试试去掉ob_start中的callback,看看有什么不同