note 50328 deleted from function.imagecreatefromjpeg by cmb

From: Date: Sun, 11 Dec 2016 11:07:38 +0000
Subject: note 50328 deleted from function.imagecreatefromjpeg by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208490@lists.php.net to get a copy of this message
Note Submitter: tl at comvironment dot com ---- I made a script to produce, save, and use dynamic buttons simultaneously. If the file exists, it will be shown as usual. If not, this script produces a new image and saves it. You only need the background (back.jpg). Maybe it is useful for somone. <?php class Button { var $ib = 'back.jpg'; var $im; function Button ($fileName, $string) { $this -> im = $fileName; if(!file_exists($this -> im)) { $this -> _createButton($string); } } function getFileName() { return $this -> im; } function _createButton($string) { $font = 4; $width = max(400,(ImageFontWidth($font) * strlen($string)) + 4); $height = max(20,(ImageFontHeight($font) + 4)); $imgBack=ImageCreateFromJPEG($this -> ib); $imgText=ImageCreateTrueColor($width,$height); $textColor = imagecolorallocate ($imgText,90,90,90); ImageCopy($imgText,$imgBack,0,0,0,0,$width,$height); ImageString ($imgText,$font,2,2,$string,$textColor); ImageJPEG($imgText,$this -> im,85); ImageDestroy($imgBack); ImageDestroy($imgText); chmod ($this -> im,0644); } } $button = new Button('button.jpg','button text'); echo '<img src="' . $button -> getFileName() . '">'; ?>

« previous php.notes (#208490) next »