用户评论:

[#1]

marc at gutt dot it [2015-03-02 22:28:20]

Based on DHKold's contribution I realized imagecreatefrombmp() to support all 1-, 4-, 8-, 16-, 24- und 32-Bit Bitmaps. Finally Fabien M??nager brought it to perfection for the project DOMPDF. Feel free to use it:

https://code.google.com/p/dompdf/source/browse/trunk/dompdf/include/functions.inc.php?spec=svn504&r=504#551

[#2]

JamesM [2010-03-26 00:03:11]

doesnt ruin the image but adds display to the output.

this will generate an image with a random color. if you like it you can use it because you have the RBG result too.

header("content-type:image/png");$im=imagecreate(100,100);$a=sprintf('%04x',mt_rand(0,65535));$b=sprintf('%04x',mt_rand(0,65535));$c=sprintf('%04x',mt_rand(0,65535));$white=imagecolorallocate($im,$a,$b,$c);imagepng($im);imagedestroy($im);

echo"\n\n\n$a-$b-$c";?>

[#3]

sk89q [2008-03-14 14:14:44]

Loads a file based on its filetype and returns false if it fails.

{$info= @getimagesize($path);

if(!$info)

{

returnfalse;

}$functions= array(IMAGETYPE_GIF=>'imagecreatefromgif',IMAGETYPE_JPEG=>'imagecreatefromjpeg',IMAGETYPE_PNG=>'imagecreatefrompng',IMAGETYPE_WBMP=>'imagecreatefromwbmp',IMAGETYPE_XBM=>'imagecreatefromwxbm',

);

if($user_functions)

{$functions[IMAGETYPE_BMP] ='imagecreatefrombmp';

}

if(!$functions[$info[2]])

{

returnfalse;

}

if(!function_exists($functions[$info[2]]))

{

returnfalse;

}

return$functions[$info[2]]($path);

}?>

[#4]

scottlindh pwnd at hushmail dot com [2007-08-19 10:40:42]

to install on UBUNTU do the following..

sudo apt-get install php5-gd

After installing the package I restarted the apache

sudo /etc/init.d/apache reload

goto love ubuntu...

[#5]

Sohel Taslim [2007-07-25 00:22:13]

It is easy and simple example to convert Text to Image with selected font.

It helps me to display Bangla text as image when users have no installed bangla font.

I hope it can help you too!

functionmakeImageF($text,$font="CENTURY.TTF",$W=200,$H=20,$X=0,$Y=0,$fsize=18,$color=array(0x0,0x0,0x0),$bgcolor=array(0xFF,0xFF,0xFF)){$im= @imagecreate($W,$H)

or die("Cannot Initialize new GD image stream");$background_color=imagecolorallocate($im,$bgcolor[0],$bgcolor[1],$bgcolor[2]);//RGB color background.$text_color=imagecolorallocate($im,$color[0],$color[1],$color[2]);//RGB color text.imagettftext($im,$fsize,$X,$Y,$fsize,$text_color,$font,$text);header("Content-type: image/gif");

returnimagegif($im);

}?>

[#6]

help at nanomc dot com [2005-11-08 11:29:37]

// A simple XY graph

XY Graph

Practice XY Graph

$left=0;$top=0;$x_size=400;$y_size=400;$char_width=8;$char_height=11;$x_start=$x_left+100;$y_start=$top+$char_height*1.5;$x_end=$x_start+$x_size;$y_end=$y_start+$y_size;$right=$x_start+$x_size+40;$bottom=$y_start+$y_size+$char_height*1.5;$graph_n=100;

for($i=0;$i

{$graph_x[$i] =$i;$graph_y[$i] =$i*$i;

}$min_x=9e99;$min_y=9e99;$max_x= -9e99;$max_y= -9e99;$avg_y=0.0;

for($i=0;$i

{

if($graph_x[$i]

if($graph_x[$i] >$max_x)$max_x=$graph_x[$i];

if($graph_y[$i]

if($graph_y[$i] >$max_y)$max_y=$graph_y[$i];$avg_y+=$graph_y[$i];

}$avg_y=$avg_y/$graph_n;$min_x=0;$min_y=0;$max_x+=$max_x*0.05;$max_y+=$max_y*0.05;$image=ImageCreate($right-$left,$bottom-$top);$background_color=imagecolorallocate($image,255,255,255);$text_color=imagecolorallocate($image,233,14,91);$grey=ImageColorAllocate($image,204,204,204);$white=imagecolorallocate($image,255,255,255);$black=imagecolorallocate($image,0,0,0);$red=imagecolorallocate($image,255,0,0);imagerectangle($image,$left,$top,$right-1,$bottom-1,$black);imagerectangle($image,$x_start,$y_start,$x_end,$y_end,$grey);

for($i=0;$i

{$pt_x=$x_start+ ($x_end-$x_start)*($graph_x[$i]-$min_x)/($max_x-$min_x);$pt_y=$y_end- ($y_end-$y_start)*($graph_y[$i]-$min_y)/($max_y-$min_y);//  imagesetpixel( $image, $pt_x, $pt_y, $black );imagechar($image,2,$pt_x-3,$pt_y-10,'.',$black);

}$string=sprintf("%2.5f",$max_y);imagestring($image,4,$x_start-strlen($string) *$char_width,$y_start-$char_width,$string,$black);$string=sprintf("%2.5f",$min_y);imagestring($image,4,$x_start-strlen($string) *$char_width,$y_end-$char_height,$string,$black);$string=sprintf("%2.5f",$min_x);imagestring($image,4,$x_start- (strlen($string) *$char_width)/2,$y_end,$string,$black);$string=sprintf("%2.5f",$max_x);imagestring($image,4,$x_end- (strlen($string) *$char_width) /2,$y_end,$string,$black);$x_title='x axis';$y_title='y axis';imagestring($image,4,$x_start+ ($x_end-$x_start) /2-strlen($x_title) *$char_width/2,$y_end,$x_title,$black);imagestring($image,4,$char_width, ($y_end-$y_start) /2,$y_title,$black);header('Content-type: image/png');$filename=sprintf("%d.png",time());ImagePNG($image,$filename);ImageDestroy($image);printf(" ",$filename);?>

[#7]

DHKold [2005-06-15 14:52:37]

to create an image from a BMP file, I made this function, that return a resource like the others ImageCreateFrom function:

{//Ouverture du fichier en mode binaireif (!$f1=fopen($filename,"rb")) returnFALSE;//1 : Chargement des ent?tes FICHIER$FILE=unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset",fread($f1,14));

if ($FILE['file_type'] !=19778) returnFALSE;//2 : Chargement des ent?tes BMP$BMP=unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.'/Vcompression/Vsize_bitmap/Vhoriz_resolution'.'/Vvert_resolution/Vcolors_used/Vcolors_important',fread($f1,40));$BMP['colors'] =pow(2,$BMP['bits_per_pixel']);

if ($BMP['size_bitmap'] ==0)$BMP['size_bitmap'] =$FILE['file_size'] -$FILE['bitmap_offset'];$BMP['bytes_per_pixel'] =$BMP['bits_per_pixel']/8;$BMP['bytes_per_pixel2'] =ceil($BMP['bytes_per_pixel']);$BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);$BMP['decal'] -=floor($BMP['width']*$BMP['bytes_per_pixel']/4);$BMP['decal'] =4-(4*$BMP['decal']);

if ($BMP['decal'] ==4)$BMP['decal'] =0;//3 : Chargement des couleurs de la palette$PALETTE= array();

if ($BMP['colors'] <16777216)

{$PALETTE=unpack('V'.$BMP['colors'],fread($f1,$BMP['colors']*4));

}//4 : Cr?ation de l'image$IMG=fread($f1,$BMP['size_bitmap']);$VIDE=chr(0);$res=imagecreatetruecolor($BMP['width'],$BMP['height']);$P=0;$Y=$BMP['height']-1;

while ($Y>=0)

{$X=0;

while ($X

{

if ($BMP['bits_per_pixel'] ==24)$COLOR=unpack("V",substr($IMG,$P,3).$VIDE);

elseif ($BMP['bits_per_pixel'] ==16)

{$COLOR=unpack("n",substr($IMG,$P,2));$COLOR[1] =$PALETTE[$COLOR[1]+1];

}

elseif ($BMP['bits_per_pixel'] ==8)

{$COLOR=unpack("n",$VIDE.substr($IMG,$P,1));$COLOR[1] =$PALETTE[$COLOR[1]+1];

}

elseif ($BMP['bits_per_pixel'] ==4)

{$COLOR=unpack("n",$VIDE.substr($IMG,floor($P),1));

if (($P*2)%2==0)$COLOR[1] = ($COLOR[1] >>4) ; else$COLOR[1] = ($COLOR[1] &0x0F);$COLOR[1] =$PALETTE[$COLOR[1]+1];

}

elseif ($BMP['bits_per_pixel'] ==1)

{$COLOR=unpack("n",$VIDE.substr($IMG,floor($P),1));

if     (($P*8)%8==0)$COLOR[1] =$COLOR[1]        >>7;

elseif (($P*8)%8==1)$COLOR[1] = ($COLOR[1] &0x40)>>6;

elseif (($P*8)%8==2)$COLOR[1] = ($COLOR[1] &0x20)>>5;

elseif (($P*8)%8==3)$COLOR[1] = ($COLOR[1] &0x10)>>4;

elseif (($P*8)%8==4)$COLOR[1] = ($COLOR[1] &0x8)>>3;

elseif (($P*8)%8==5)$COLOR[1] = ($COLOR[1] &0x4)>>2;

elseif (($P*8)%8==6)$COLOR[1] = ($COLOR[1] &0x2)>>1;

elseif (($P*8)%8==7)$COLOR[1] = ($COLOR[1] &0x1);$COLOR[1] =$PALETTE[$COLOR[1]+1];

}

else

returnFALSE;imagesetpixel($res,$X,$Y,$COLOR[1]);$X++;$P+=$BMP['bytes_per_pixel'];

}$Y--;$P+=$BMP['decal'];

}//Fermeture du fichierfclose($f1);

return$res;

}?>

[#8]

[2005-01-05 13:30:35]

This is how you can create a thumbnail with maximum height and width. This way it will fit nicely in a gallery table. In this example $im is the source image

if($oh>$maxh||$ow>$maxw){$new_h= ($oh>$ow) ?$maxh:$oh*($maxw/$ow);$new_w=$new_h/$oh*$ow;

}//create dst image$dst_img=ImageCreateTrueColor($new_w,$new_h);//resize and copy imageImageCopyResized($dst_img,$im,0,0,0,0,$new_w,$new_h,ImageSX($im),ImageSY($im));$function_image_new($dst_img,$galdir.$file);?>

[#9]

cstevens at gencom dot us [2004-04-20 16:56:48]

Here's how I resolved the "Fatal error: Call to undefined function: imagecreate()" error using Gentoo:

1) add a USE flag for gdb in /etc/make.conf

USE="3dnow avi [whatever else you have] gdb"

Note: here's a list of all of the USE flags:

http://www.gentoo.org/dyn/use-index.xml

2) unmerged mod_php

*Note* It could take awhile to "remerge" as it may need to compile several dependancies...do this during not production hours and have a backup if you absolutely cannot have downtime

emerge -C mod_php

3) emerged mod_php

emerge -p mod_php

# find out if it's going to take awhile

4) edit /etc/php/apach2-php4/php.ini

uncomment the "extension=php_gd2.dll" line

5) Restart apache2

/etc/init.d/apache2 restart

Hope this helps!

--

Cooper Stevenson

GenCom

http://www.gencom.us

[#10]

foxlovr1 at cox dot net [2004-04-12 16:11:56]

You can set it up so you can write a text which is controled from the URL.

Like this...

header("Content-type: image/png");$im= @imagecreate(128,16) or die("Cannot Initialize new GD image stream");$bc=imagecolorallocate($im,0,255,255);$tc=imagecolorallocate($im,0,0,0);imagestring($im,1,4,4,$t,$tc);imagepng($im);imagedestroy($im);?>

Then when you use the image, use this...

This will create an image with a cyan background, and in black text it will say "Text"

EMail me at foxlovr1@cox.net or aquafox90@yahoo.com for comments/questions.

[#11]

sjnorrie at hotmail dot com [2003-12-03 11:07:21]

On windows.

When you get undefined function image* it means the gd library isnt being used. Check the php.ini file. Make sure the php_gd.dll isnt commented out. Restarting apache should result in the image functions working.

[#12]

tassader at xmail dot cz [2003-10-21 08:55:49]

It seems that imagecreate creates a grayscale image with gd2

[#13]

tore at kyberheimen dot com [2002-08-29 14:33:37]

GD UPGRADE PROBLEM:

I used imagecreate with gd 1.6 to make resized images of big photos. Then, when using the same script on gd 2.0, the colors got all wrong.

Using imagecreatetruecolor() fixed the problem!

[#14]

php at silisoftware dot com [2002-05-17 10:17:09]

Don't try and create an image with a really large width and/or height. First, $width x $height is (at least) the bytes of memory that need to be allocated. Secondly, if you exceed the range of int for either parameter, Apache crashes (before allocating any memory).

Don't ask how I figured this out ;)

[#15]

robert at scpallas dot de [2002-02-08 08:09:08]

The function ImageCreate() creates a PALETTE image.

The function ImageCreateFromJPEG() creates a TRUE COLOR image.

When you use GD 2.0 you will get an error when you try to use ImageCopy()

with one True color image and one Palette image.

Be sure to convert one of the images before using ImageCopy() or use ImageCreateTrueColor() instead of ImageCreate().

[#16]

andrus at vnet dot ee [2001-07-08 09:09:33]

Dont forget to use ImageDestoy after showed image. I forgot it, my webpage had about 15 pictures what was generated by GD and webserver died very fastly (server was Dual Xeon 900MHz and 4G RAM :[[ ). It died cos of not enough memory :\

[#17]

wouter at rusman dot net [2001-07-06 05:31:04]

to compile GD support on some linux distributions you have to include these with the ./configure command :

--with=gd=/usr --with-jpeg=/usr --with-png=/usr --with-zlib=/usr

(i had to include this on Redhat 6.1)

this becase the libraries are in /usr/lib instead of /lib

[#18]

altype at bellsouth dot net [2001-04-19 16:13:36]

ImagePNG($pic,"./dir/pic.png");

To save image as a file, I had to create a directory "dir" and CHMOD 777 to give read, write, and execute permission for everyone - or it wouldn't save it...

[#19]

removethisbeforebayet at removethistooenseirb dot fr [2001-02-08 15:00:37]

Pay attention to a problem I encountered.

Png images created with the PHP function seems to be very badly recognised by old browsers, especially -well, mainly - by IE 4.0 (crash of the browser).

I think this is probably due to the fact that, when IE 4.0 was released, the png format was either very recent, either not very used, because of the widespread jpeg and gif formats...

So, if you plan to dynamically create images for a web site to be seen by IE 4.0 users, think of it...

May'be the jpeg format will do the job better.

[#20]

kim at kimmccall dot org [2000-12-14 04:22:03]

How I fixed my "undefined function imagecreate()" problem:

I was having the same problem many have reported where most of PHP worked but the gd functions didn't.  I'd installed the RedHat rpm php-4.0.1pl2.  It said (phpinfo.php) that it had been configured with the '--with-gd=shared' option.  In my /usr/lib directory, I had both libgd.so.1.8.3 and libgd.a.  I decided to compile with the static library instead, so I downloaded the sources and built with all the same configuration flags except that I used --with-gd=/usr.  Now my gd library works!!!

php imagecreate 中文,imagecreate相关推荐

  1. unity3D AR涂涂乐制作浅谈

    unity3D AR涂涂乐制作浅谈 AR为现在是虚拟现实较为火爆的一个技术,其中有个比较炫酷的就是AR涂涂乐的玩法,这个技术可以把扫描到的图片上的纹理 粘贴到模型上实现为模型上色的功能,但是我们需要怎 ...

  2. v2v-VMware/VSphere中虚机手动迁移至openstack平台

    前言 前一阵子写了篇v2v的博客,主要是倾向于如何使用virt-v2v工具将VSphere平台虚机进行跨平台迁移至KVM环境中.对手动迁移叙述的不够详细,并且对手动手动迁移中的细节描述的也不够具体.在 ...

  3. php渐变,PHP绘制渐变颜色图片

    原文在: http://planetozh.com/blog/my-projects/images-php-gd-gradient-fill/ 使用范例如下,基本函数封装在gd-gradient-fi ...

  4. glance image-create

    glance image-create

  5. php5.6.30环境报错Call to undefined function ImageCreate() 编译安装 gd库

    php5.6.30环境报错Call to undefined function ImageCreate() 编译安装 gd库发现php5.6.30没有加载gd库[root@cn_vs_web04:/u ...

  6. php image处理,PHP图像处理之imagecreate、imagedestroy函数介绍

    使用PHP的GD库处理图像时,必须对画布进行管理.创建画布就是在内存中开辟一块存储区域,以后在PHP中对图像的所有操作都是基于这个图布处理的,图布就是一个图像资源.在PHP中,可以使用imagecre ...

  7. PHP发生Call to undefined function imagecreate()错误的解决办法

    在使用php处理一些图像时,有时会出现诸如这样的错误:Call to undefined function imagecreate() 这是由于没有安装或是没有开启php的gd库导致的问题. 解决方案 ...

  8. php如何开发调色器,PHP imagecreate - 新建一个基于调色板的图像

    imagecolorallocate - 新建一个基于调色板的图像. 语法 imagecreate ( int $x_size , int $y_size ) : resource imagecolo ...

  9. PHP imagecreate - 生成自定义图片

    PHP imagecreate - 生成自定义图片 该方法是根据字符的长度改变字体的大小 function generateCover($content,$author,$date)//$conten ...

最新文章

  1. CSS将样式规则与HTML元素相关联
  2. 1.18.2.Table APISQL(概念与通用API、两种计划器(Planner)的主要区别、创建 TableEnvironment、临时表、永久表、创建表、虚拟表、Connector 等)
  3. 计算机如何学会自动地进行图像美学增强?
  4. python图片横向合并_[宜配屋]听图阁
  5. 基于JAVA+SpringMVC+Mybatis+MYSQL的软件办公管理系统
  6. 与其临渊羡鱼,不如退而结网
  7. 统计计算机考试题,销售统计表计算机windows一级最新考试试题
  8. lisp princ详解_LISP教程
  9. Altium Designer
  10. MASM5.0下载安装与运行第一个HelloWorld
  11. 数据安全:Mock数据
  12. 深度解析Contains底层代码
  13. html银河特效编码,html5 canvas银河星系动画特效
  14. 修改html2canvas生成图片的dpi
  15. Oracle Smart Flash 新特性性能测试说明
  16. 下载支付宝秘钥生成工具
  17. [附源码]计算机毕业设计JAVA基于JSP社区生鲜配送系统
  18. 中控考勤机连服务器显示1007,中控智慧ZK-S1007动态人脸识别考勤门禁终端
  19. 进程间通信和线程间通信的几种方式
  20. 为什么IT行业这么火?

热门文章

  1. 好用的jpg转pdf软件
  2. can only concatenate str (not “NoneType“) to str
  3. 双三次插值法(Bicubic interpolation)
  4. QT基础入门【调试篇】QT程序如何打包发布生成可执行exe文件(win下的可执行程序)
  5. 流行创意风格教师求职简历免费word模板
  6. echarts 调色盘、渐变色
  7. 大学计算机组织部面试问题及答案,组织部面试问题及答案_学生会组织部面试技巧...
  8. 回溯法简单应用--解数独
  9. linux桌面管理器未激活,聊聊linux桌面环境和包管理器
  10. 新blog开张...