赞
踩
目前支持三种图片格式 png , gif , jpeg
- class image_str
- {
- private $img_src; //图片路径 eg: 'logo.png'
-
- private $img_info_type; //construcr type : string
- private $font_size; // ... type : int
-
- private $the_image; //图像标识符
-
- private $x; // width int
- private $y; // height int
-
- function __construct($src)
- {
- $this->img_src = $src;
-
- $img_info = getimagesize($this->img_src);
-
- $this->x = $img_info[0];
- $this->y = $img_info[1];
-
- $this->img_info_type = $img_info['mime'];
-
- $this->font_size = 2;
- }
-
- function get_info()
- {
- echo $this->img_info_type;
- }
-
- public function select()
- {
- switch ($this->img_info_type)
- {
- case 'image/png':
- $this->the_image = imagecreatefrompng($this->img_src);
- break;
- case 'image/gif':
- $this->the_image = imagecreatefromgif($this->img_src);
- break;
- case 'image/jpeg':
- $this->the_image = imagecreatefromjpeg($this->img_src);
- break;
- default :
- $this->image_error();
-
- }
- $this->image();
- }
-
- private function image() // main function
- {
-
- if(! $this->the_image )
- {
- $this->the_image = imagecreate(200,300);
- $bg = imagecolorallocate($this->the_image,255,0,0);
- }
-
- $color_str = imagecolorallocate($this->the_image,255,255,255);
-
- imagestring( $this->the_image, $this->font_size, 15, $this->y - 20, "hello,world", $color_str );
- }
-
- public function get_image()
- {
- header('Content-type:'.$this->img_info_type);
- imagepng($this->the_image);
- }
- }
-
-
-
- $image = new image_str('logo.png');
- $image->select();
- $image->get_image();
- $image->get_info();
不过无关紧要,get_info()仅是用来测试的。
好吧,就到这,这很简单
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。