setImageType("jpg"); // image type => jpg/gif/png $this->setText($text); // text string } // PHP 4 /*function TextToImage($text = "") { $this->__construct($text); }*/ /** ** Getters **/ function getText() { return $this->text; } function getImagePath() { return $this->path; } function getImageType() { return $this->imgType; } /** ** Setters **/ function setText($text) { $this->text = (empty($text)) ? "" : $text; } function setImagePath($path = "./") { if(substr($path, -1, 1) != "/") $path .= "/"; $this->path = $path; } // // Set Image Type // function setImageType($type) { $this->imgType = strtolower($type); } /** ** Behaviors **/ function create() { header("Content-type: image/{$this->imgType}"); $this->render(); switch($this->imgType) { case "png" : imagepng($this->img); break; case "gif" : imagegif($this->img); break; case "jpg" : default: imagejpeg($this->img, null, 100); } $this->__destruct(); } function save($filename = "") { $filename = (empty($filename)) ? date("YmdHis") : $filename; $filename .= ".{$this->imgType}"; // setting filename $filename = $this->path.$filename; // image path $this->render(); switch($this->imgType) { case "png" : imagepng($this->img, $filename); break; case "gif" : imagegif($this->img, $filename); break; case "jpg" : default: imagejpeg($this->img, $filename, 100); } $this->__destruct(); return $filename; } private function render() { // Init GD // config width and height of the image $width = ($this->fontSize + 1.5) * (strlen($this->text)); $height = $this->fontSize * 3.5; // create image, background, and textcolor $this->img = imagecreate($width, $height) or DIE("Cannot Initialize new GD image stream"); $this->bgColor = imagecolorallocate($this->img, 255, 255, 255); $this->txtColor = imagecolorallocate($this->img, 0, 0, 0); imagestring($this->img, $this->fontSize, 5, 5, $this->text, $this->txtColor); } /** * Destructor */ function __destruct() { @imagedestroy($this->img); } } /** * Helper */ if(isset($_GET['texttoimage']) && !empty($_GET['texttoimage'])) { $img = new TextToImage($_GET['texttoimage']); $img->create(); } $text = "Srbuj makar slamu jeo :)"; $img1 = new TextToImage($text); $img1->create(); ?>