Skip to content

Instantly share code, notes, and snippets.

@rodrigo-x
Last active October 13, 2015 19:48
Show Gist options
  • Save rodrigo-x/4246606 to your computer and use it in GitHub Desktop.
Save rodrigo-x/4246606 to your computer and use it in GitHub Desktop.
Image with GD...
<?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