Skip to content

Instantly share code, notes, and snippets.

@udonchan
Created December 6, 2010 16:45
Show Gist options
  • Save udonchan/730547 to your computer and use it in GitHub Desktop.
Save udonchan/730547 to your computer and use it in GitHub Desktop.
日付入れる裏蓋をシミュレート
<?php
class Urabuta {
const datetime_original_format = 'Y:m:d H:i:s';
const datetime_output_format = '\'y m d';
private $date_time;
private $image;
public function __construct($photo) {
$exif_data = exif_read_data($photo);
$this->date_time = DateTime::createFromFormat(self::datetime_original_format, $exif_data['DateTimeOriginal']);
$this->image = new Imagick($photo);
}
public function dateTime(){
return $this->date_time;
}
public function dateTimeText(){
return $this->date_time->format(self::datetime_output_format);
}
public function output($width=0){
if($is_rotate = ($this->image->getImageWidth() < $this->image->getImageHeight()))
$this->image->rotateImage('none', 90);
$annot = new Imagick();
$annot->newImage($this->image->getImageWidth(), $this->image->getImageHeight(), 'none');
$draw = new ImagickDraw();
$draw->setGravity(imagick::GRAVITY_SOUTHEAST);
$draw->setFillColor(new ImagickPixel('#FFAC00'));
$draw->setFont('YournameD7EnterpriseCondensed.ttf');
$draw->setFontSize($annot->getImageHeight() * 0.048);
$annot->annotateImage($draw, $annot->getImageWidth() * 0.1 , $annot->getImageHeight() * 0.1, 0, $this->dateTimeText());
$annot->gaussianBlurImage($annot->getImageWidth() * 0.001, $annot->getImageWidth() * 0.01);
$this->image->compositeImage($annot, Imagick::COMPOSITE_HARDLIGHT, 0, 0);
if($width != 0)
$this->image->thumbnailimage($width, $this->image->getImageHeight() * $width / $this->image->getImageWidth());
if($is_rotate)
$this->image->rotateImage('none', -90);
header("Content-Type: image/{$this->image->getImageFormat()}");
echo $this->image;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment