Last active
October 13, 2015 19:48
-
-
Save rodrigo-x/4246606 to your computer and use it in GitHub Desktop.
Image with GD...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Image { | |
private $img; | |
private $text; | |
private $fontsize; | |
public function __construct( $img, $text, $fontsize ) { | |
$this->img = $img; | |
$this->text = $text; | |
$this->fontsize = $fontsize; | |
} | |
public function create() { | |
if ( !empty( $this->img ) ) { | |
$this->img = imagecreatefromjpeg( $this->img ); | |
$red = imagecolorallocate( $this->img, 255, 0, 0 ); | |
$green = imagecolorallocate( $this->img, 0, 255, 0 ); | |
$width = imagesx( $this->img ); | |
$height = imagesy( $this->img ); | |
$pos = ( $width - imagefontwidth( $this->fontsize ) * STRLEN( $this->text ) ); | |
imagestring( $this->img, $this->fontsize, $pos, $height-18, $this->text, $red ); | |
header( 'Content-type: image/jpeg' ); | |
imagejpeg( $this->img ); | |
imagedestroy( $this->img ); | |
} else { | |
throw new Exception( 'Unable to load Image...' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment