PHP图象处理的函数imagecreatefromstring,可以直接将二进制图像字串(数据流)创建成图像资源。
因而,使用此函数免去了大量的文件IO。
比如,我们可以在必要时用imagegd2或imagegif等函数输出。但我们可以控制其输出到我们所要的变量中。如同以下代码:
function _image_to_buffer($resource){
ob_start();
imagegif($resource);
$output_buf= ob_get_contents();
ob_end_clean();
return $output_buf;
}
然后,再用imagecreatefromstring去做进一步的操作。也许你会说,这可能没有这样的必要。但是,对于GIF动画的处理,比如,完成功能如:resize animatedt gif,water mark animatedt gif等,就有可能必须要这样做。
但很奇怪的是:imagecreatefromstring,当图象小于GIF的实际逻辑屏幕定义,并且 image left possition和image top possition不为0时,imagecreatefromstring会将此二者改为0,同时,图象不再是实际逻辑屏幕定义长与宽,而是image descroptor中的长与宽。不太清楚,这是否属于PHP图像处理函数的一个BUG。
并且,很让人遗憾的是 imagemagik 针对GIF动画制作缩略图时,也有这样的问题。 这样,原来的动画就出问题了。本来该在下面动的物体跑到了左上角。
因此,对于imagecreatefromstring,必须要另想办法,来改变这一个问题。
$data = $this->get_frame_data($i);
$tmp_im = imagecreatefromstring ($data);
$w= imagesx($tmp_im);
$h= imagesy($tmp_im);
$left_pos = $this->_word_to_int($this->gif_frames[$i]['img_dsc']['img_left_pos']);
$top_pos = $this->_word_to_int($this->gif_frames[$i]['img_dsc']['img_top_pos']);
$img_w = $this->_word_to_int($this->gif_frames[$i]['img_dsc']['img_w']);
$img_h = $this->_word_to_int($this->gif_frames[$i]['img_dsc']['img_h']);
if (($w< $this->gif_lsd['ls_w'])||($h<$this->gif_lsd['ls_h'])){
$fra_im=imagecreatetruecolor($this->gif_lsd['ls_w'],$this->gif_lsd['ls_h']);
if ($this->gif_frames[$i]['grph_ctrl_ext']['transparent']==1){
$color = $this->gif_gct['data'][$this->gif_frames[$i]['grph_ctrl_ext']['transparent_clr_idx']];
imagepalettecopy($fra_im,$tmp_im);
imagecolortransparent($fra_im,$color);
imagefilledrectangle($fra_im,0,0,$this->gif_lsd['ls_w'],$this->gif_lsd['ls_h'],$color);
}
imagecopy ($fra_im, $tmp_im, $left_pos, $top_pos, 0, 0, $img_w, $img_h);
}
else
$fra_im=$tmp_im;
这样,再用 $fra_im就正确了。
分享到:
相关推荐
gif_jpeg_png系列函数用法,结合实例形式分析了php的图像载入函数imagecreatefromgif、imagecreatefromjpeg、imagecreatefrompng、imagecreatefromwbmp及imagecreatefromstring使用技巧,需要的朋友可以参考下
1、介绍PHP水印原理和流程 2、ImageCreateFrom* 图片载入函数 imagecreatefromgif imagecreatefromjpeg ... imagecreatefromstring 3、imagecopy 图片合并函数 4、ImageCopyResized图片剪切函数
1、介绍PHP水印原理和流程2、ImageCreateFrom* 图片载入函数 imagecreatefromgif imagecreatefromjpeg imagecreatefrompng imagecreatefromwbmp imagecreatefromstring3、imagecopy 图片合并函数4、...
API 是稳定的,但任一方向的散列函数可能都不稳定。 Blurhash 是由为编写的算法,可将图像编码为短(~20-30 字节)ASCII 字符串。 当您将字符串解码回图像时,您将获得代表原始图像的渐变颜色。 这对于在加载前需要...
软件介绍 1、介绍PHP水印原理和流程 2、ImageCreateFrom* 图片载入函数 imagecreatefromgif imagecreatefromjpeg ... imagecreatefromstring 3、imagecopy 图片合并函数 4、ImageCopyResized图片剪切函数
下面贴处理的源代码: 复制代码 代码如下: <?php require_once(“gifencoder.php”); //载入编码 文件 $gif = new GIFEncoder(); //实例化gif解码对象 $gif->load(“test.gif”); //载入要解码的gif图像 for($...
/*imagecreatefromstring()--从字符串中的图像流新建一个图像,返回一个图像标示符,其表达了从给定字符串得来的图像 图像格式将自动监测,只要php支持jpeg,png,gif,wbmp,gd2.*/ $font = './t1.ttf'; $bl
$QR = imagecreatefromstring(file_get_contents($QRUrl)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); //二维码图片宽度 $QR_height = imagesy($QR...
当使用苹果的iOS系统拍照上传图片的时候,可能会遇到图片被旋转的问题,这主要是取决于你拍照时拍照按钮的位置。假设拍照时你把手机旋转过来底部朝上,那拍出来的照片也是被旋转了的。 下面的代码将确保所有上传的...
////$imgsrc = imagecreatefromstring($strimgsrc); $imgsrc = imagecreatefromjpeg(“5307754.jpg”); $imgsrcw = imagesx($imgsrc); $imgsrch = imagesy($imgsrc); $width = 30; $x1 = 2; $x2 = $imgsrcw – $x1 ...
$im = imagecreatefromstring($imgstream); $x = imagesx($im);//获取图片的宽 $y = imagesy($im);//获取图片的高 // 缩略后的大小 $xx = 140; $yy = 200; if($x>$y){ //图片宽大于高 $sx = abs(($y-$x)/2); $sy =...
$dst = imagecreatefromstring(file_get_contents($dst_path)); $src = imagecreatefromstring(file_get_contents($src_path)); //获取水印图片的宽高 list($src_w, $src_h) = getimagesize($src_...
//创建图片的实例$dst = imagecreatefromstring(file_get_contents($dst_path)); //打上文字$font = ‘./simsun.ttc’;//字体$black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色imagefttext($...
一 imageCreateFrom* 图片载入函数 //针对不同的后缀名图片 imagecreatefromgif imagecreatefromjpeg imagecreatefrompng imagecreatefromwbmp imagecreatefromstring 使用格式:imagecreatefromgif(“jjj.gif”);...
//创建源图的实例$src = imagecreatefromstring(file_get_contents($src_path));//裁剪开区域左上角的点的坐标$x = 100;$y = 12;//裁剪区域的宽和高$width = 200;$height = 200;//最终保存成图片的宽和高,...