note 50328 added to function.imagecreatefromjpeg
| From: | tlatcomvironmentdotcom at osu1 dot php dot net | Date: | Thu, 24 Feb 2005 21:53:12 +0000 |
| Subject: | note 50328 added to function.imagecreatefromjpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85488@lists.php.net to get a copy of this message | ||
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() . '">';
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatefromjpeg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50328
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50328&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50328&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50328&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50328&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50328&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50328&report=yes
Search -- http://master.php.net/manage/user-notes.php