note 49695 added to ref.image

From: Date: Sat, 05 Feb 2005 07:08:18 +0000
Subject: note 49695 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-84549@lists.php.net to get a copy of this message
I wrote a class for easy to draw string on a picture. you do only such as: $string = $_GET['text']; $img=new pullImage("image/bar13.png", 8,0,0,"12345678","png"); $img->setPaintColor(10,222,200); $img->setPaintSize(8); $img->setDrawText($string); $img->DrawText(); here is the pullImage class: class pullImage{ var $img_font_size=3; var $origin_file_path=""; var $paint_color=array(0,0,0); var $im=0; var $poision_x=0; var $poision_y=0; var $poision_z=0; var $pull_text="testing"; var $pull_image_type="png"; function pullImage($source_file_path="",$front_size=3, $p_x=0,$p_y=0,$draw_text="png",$picture_type="png") { $this->img_font_size=$front_size; $this->origin_file_path=$source_file_path; $this->poision_x=$p_x; $this->poision_y=$p_y; $this->pull_image_type=$picture_type; $this->pull_text=$draw_text; } function setPaintColor($red=0,$green=0,$blue=0) { $this->paint_color[0]=$red; $this->paint_color[1]=$green; $this->paint_color[2]=$blue; } function setPaintSize($fontsize) { $this->img_font_size=$fontsize; } function setImageType($type) { $this->pull_image_type=$type; } function setDrawText($txt) { $this->pull_text=$txt; } function DrawText() { $this->im=$this->createImgageFormFile(); if(!$this->im) { $this->responseError(); return; } $paint_color=$this->fill_solid_color($this->im); $c_width = ImageFontWidth($this->img_font_size) * strlen($this->pull_text); $c_height = ImageFontHeight($this->img_font_size); $px = (imagesx($this->im) - $c_width) / 2; $py = (imagesy($this->im)-$c_height)/2; $this->pull_header(); imagestring($this->im, $this->img_font_size, $px, $py, $this->pull_text, $paint_color); $this->pull_Image($this->im); imagedestroy($this->im); } function responseError() { echo("<p>Can't create image!</p>"); } function pull_header() { switch(strtolower($this->pull_image_type)) { case "png": header("Content-type: image/png"); break; case "jpg": header("Content-type: image/jpeg"); break; case "gif": header("Content-type: image/gif"); default: header("Content-type: image/png"); break; } } function pull_Image($im) { if(!$im)return; switch(strtolower($this->pull_image_type)) { case "png": @imagepng($im); break; case "jpg": @imagejpeg($im); break; case "gif": @imagegif($im); default: @imagepng($im); break; } } function createImgageFormFile() { $im=0; if($this->origin_file_path=="") return $im; switch(strtolower($this->pull_image_type)) { case "png": $im=@imagecreatefrompng($this->origin_file_path); break; case "jpg": $im=@imagecreatefromjpg($this->origin_file_path); break; case "gif": $im=@imagecreatefromgif($this->origin_file_path); default: $im=@imagecreatefrompng($this->origin_file_path); break; } if(!$im) { $im = @imagecreate (120, 40); /* Create a blank image */ $bgc = @imagecolorallocate ($im, 255, 255, 255); @imagefilledrectangle ($im, 0, 0, 120, 40, $bgc); } return $im; } function fill_solid_color($im) { $ret=@imagecolorallocate($im,$this->paint_color[0], $this->paint_color[1],$this->paint_color[2]); return $ret; } } ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49695 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49695&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49695&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49695&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49695&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49695&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49695&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84549) next »