php imagecopyresized实例
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,看看有什么不同
相关文章
- 马上圣诞节了,作为一名程序猿,如何体现自己独特的过节风格,如何在朋友圈发一张专属自己的祝福照片我觉得很有必要,你们说是不是...2015-12-25
- 主键与外键的关系,通俗点儿讲,我现在有一个论坛,有两张表,一张是主贴 thread,一张是回帖 reply先说说主键,主键是表里面唯一识别记录的字段,一般是帖子id,体现在访问的时候,例如是 thread.php?id=1 表示我要访问的是帖子...2015-11-24
- 这篇文章主要介绍了微信小程序 Image API实例详解的相关资料,需要的朋友可以参考下...2016-10-02
- 这篇文章主要介绍了c#接口使用的实例,文中讲解非常细致,代码帮助大家更好的理解和学习,感兴趣的朋友可以了解下...2020-07-17
- 一、数据访问对象 (DAO)YiiDAO 基于 PHP Data Objects (PDO) 构建。它是一个为众多流行的DBMS提供统一数据访问的扩展,这些 DBMS 包括MySQL, PostgreSQL 等等。因此,要使用 Yii DAO,PDO 扩展和特定的 PDO 数据库驱动(例如...2015-11-24
- 这篇文章主要给大家介绍了关于JS如何监听div的resize事件的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-04
- 这篇文章介绍了C# byte数组与Image相互转换的方法,有需要的朋友可以参考一下...2020-06-25
- 这篇文章主要介绍了C#中的IEnumerable简介及简单实现实例,本文讲解了IEnumerable一些知识并给出了一个简单的实现,需要的朋友可以参考下...2020-06-25
php resizeimage 部分jpg文件 生成缩略图失败的原因分析及解决办法
这篇文章主要介绍了php resizeimage 部分jpg文件 生成缩略图失败的原因分析及解决办法的相关资料,需要的朋友可以参考下...2016-03-27- 在这一章里你将了解到迷人而又让人容易糊涂的套接字(Sockets)。Sockets在PHP中是没有充分利用的功能。今天你将看到产生一个能使用客户端连接的服务器,并在客户端使用sock...2016-11-25
- 图加广告是在网站页面上经常会用到的添加广告方法之一,那么在ad-imageplus 图加广告中又要如何实现呢?下面一聚教程网为大家带来了详细的使用方法,希望对大家有所帮助。...2016-12-21
- 这篇文章主要介绍了利用C++内核对象封装的类,程序只能运行单个实例,可防止多次启动,大家参考使用吧...2020-04-25
- ob_start([string output_callback])- 打开输出缓冲区 所有的输出信息不在直接发送到浏览器,而是保存在输出缓冲区里面,可选得回调函数用于处理输出结果信息。 ob...2016-11-25
- 这篇文章主要介绍了优化mysql之key_buffer_size设置的相关资料,需要的朋友可以参考下...2016-06-12
- 这篇文章主要为大家详细介绍了Vue实例的一些简单方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-01-23
- 这篇文章主要介绍了Vue实例的选项有哪些,文中讲解非常细致,代码帮助大家更好的学习,感兴趣的朋友可以了解下...2020-06-10
- 今天研究了一下,在C#里面却是可以不用自定义消息这么复杂的方法来实现跨窗体调用控件,C#有更好的办法就是委托。...2020-06-25
- 下面我们来介绍一下关于php实现断点续传的代码,有需要学习的朋友可参考一下。 让PHP下载代码支持断点续传 主要靠的 HTTP协议中header Content-Range来实现 先来...2016-11-25
- 本文我们来分享一段可以同时ping多个ip然后对比找出网络最快的ip的php程序,这段程序用来找代理ip可是神器。 为了翻墙方便 ,买了个vpn,转到osx下面官方没有提供合...2016-11-25
- imageantialias (PHP 4 >= 4.3.2, PHP 5) 描述 布尔imageantialias($sourc,$bool) 激活的行反走样快速绘制方法和有线多边形。它不支持阿尔法组件。它可以使用直接混...2016-11-25