This commit is contained in:
jygaulier
2013-03-13 16:10:00 +01:00
parent 5121fe275f
commit 360c09c3fd

View File

@@ -9,8 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\Process\ProcessBuilder; // use Symfony\Component\Process\ProcessBuilder;
use PHPExiftool\Reader; // use PHPExiftool\Reader;
use MediaVorus\Media\Media;
use Imagine\Image\ImagineInterface; use Imagine\Image\ImagineInterface;
use Imagine\Image\Color; use Imagine\Image\Color;
use Imagine\Image\Box; use Imagine\Image\Box;
@@ -36,7 +37,7 @@ class recordutils_image extends recordutils
* @param int $width * @param int $width
* @return Array * @return Array
*/ */
protected function wrap(&$imagine, $fontSize, $angle, $fontFace, $string, $width) protected function wrap(ImagineInterface $imagine, $fontSize, $angle, $fontFace, $string, $width)
{ {
// str 'Op' used to calculate linespace // str 'Op' used to calculate linespace
$font = $imagine->font($fontFace, $fontSize, new Color("000000", 0)); $font = $imagine->font($fontFace, $fontSize, new Color("000000", 0));
@@ -58,7 +59,7 @@ class recordutils_image extends recordutils
for ($i = 0; $i < strlen($lig); $i++) { for ($i = 0; $i < strlen($lig); $i++) {
$c = $lig[$i]; $c = $lig[$i];
if ($iword == -1 || (ctype_space($c) && !ctype_space($lastc))) { if ($iword == -1 || (ctype_space($c) && !ctype_space($lastc))) {
$twords[++$iword] = array(($part = 0) => '', 1 => ''); $twords[++$iword] = array(($part = 0) => '', 1 => '');
} }
if (!ctype_space($c) && $part == 0) { if (!ctype_space($c) && $part == 0) {
$part++; $part++;
@@ -135,15 +136,13 @@ class recordutils_image extends recordutils
return $subdef->get_pathfile(); return $subdef->get_pathfile();
} }
$rotation = NULL; $rotation = null;
try { try {
$reader = new Reader(); $image = $Core['mediavorus']->guess(new SplFileInfo($subdef->get_pathfile()));
$metadatas = $reader if (Media::TYPE_IMAGE === $image->getType()) {
->files($subdef->get_pathfile()) // One of MediaVorus\Media\Image::ORIENTATION_* constants
->first()->getMetadatas(); $rotation = $image->getOrientation();
$r = $metadatas['IFD0:Orientation']; }
if ($r)
$rotation = trim($r->getValue());
} catch (Exception $e) { } catch (Exception $e) {
// getting orientation failed but we don't care the reason // getting orientation failed but we don't care the reason
} }
@@ -189,18 +188,18 @@ class recordutils_image extends recordutils
$image_in = $imagine->open($pathIn); $image_in = $imagine->open($pathIn);
$image_size = $image_in->getSize(); $image_size = $image_in->getSize();
switch ($rotation) { switch ($rotation) {
case 6: case MediaVorus\Media\Image::ORIENTATION_90:
$image_width = $image_size->getHeight(); $image_width = $image_size->getHeight();
$image_height = $image_size->getWidth(); $image_height = $image_size->getWidth();
$image_in->rotate(90); $image_in->rotate(90);
$rotation = '90'; $rotation = '90';
break; break;
case 8: case MediaVorus\Media\Image::ORIENTATION_270:
$image_width = $image_size->getHeight(); $image_width = $image_size->getHeight();
$image_height = $image_size->getWidth(); $image_height = $image_size->getWidth();
$image_in->rotate(270); $image_in->rotate(270);
break; break;
case 3: case MediaVorus\Media\Image::ORIENTATION_180:
$image_width = $image_size->getWidth(); $image_width = $image_size->getWidth();
$image_height = $image_size->getHeight(); $image_height = $image_size->getHeight();
$image_in->rotate(180); $image_in->rotate(180);
@@ -442,9 +441,7 @@ class recordutils_image extends recordutils
return $subdef->get_pathfile(); return $subdef->get_pathfile();
} }
/**
/**
* *
* @param \media_subdef $subdef * @param \media_subdef $subdef
* @return boolean|string * @return boolean|string
@@ -485,59 +482,57 @@ class recordutils_image extends recordutils
} }
$in_image = $imagine->open($pathIn); $in_image = $imagine->open($pathIn);
$in_size = $in_image->getSize(); $in_size = $in_image->getSize();
$in_w = $in_size->getWidth(); $in_w = $in_size->getWidth();
$in_h = $in_size->getHeight(); $in_h = $in_size->getHeight();
$wm_file = $registry->get('GV_RootPath') . 'config/wm/' . $base_id; $wm_file = $registry->get('GV_RootPath') . 'config/wm/' . $base_id;
if (file_exists($wm_file)) { if (file_exists($wm_file)) {
$wm_image = $imagine->open($wm_file); $wm_image = $imagine->open($wm_file);
$wm_size = $wm_image->getSize(); $wm_size = $wm_image->getSize();
$wm_w = $wm_size->getWidth(); $wm_w = $wm_size->getWidth();
$wm_h = $wm_size->getHeight(); $wm_h = $wm_size->getHeight();
if(($wm_w/$wm_h) > ($in_w/$in_h)) { if (($wm_w / $wm_h) > ($in_w / $in_h)) {
$wm_size = $wm_size->widen($in_w); $wm_size = $wm_size->widen($in_w);
} } else {
else { $wm_size = $wm_size->heighten($in_h);
$wm_size = $wm_size->heighten($in_h); }
} $wm_image->resize($wm_size);
$wm_image->resize($wm_size);
$in_image->paste($wm_image, new Point(($in_w-$wm_size->getWidth())>>1, ($in_h-$wm_size->getHeight())>>1))->save($pathOut); $in_image->paste($wm_image, new Point(($in_w - $wm_size->getWidth()) >> 1, ($in_h - $wm_size->getHeight()) >> 1))->save($pathOut);
} } else {
else { $collname = phrasea::bas_names($base_id);
$collname = phrasea::bas_names($base_id); $draw = $in_image->draw();
$draw = $in_image->draw(); $black = new Color("000000");
$black = new Color("000000"); $white = new Color("FFFFFF");
$white = new Color("FFFFFF"); $draw->line(new Point(0, 1), new Point($in_w - 2, $in_h - 1), $black);
$draw->line(new Point(0, 1), new Point($in_w-2, $in_h-1), $black); $draw->line(new Point(1, 0), new Point($in_w - 1, $in_h - 2), $white);
$draw->line(new Point(1, 0), new Point($in_w-1, $in_h-2), $white); $draw->line(new Point(0, $in_h - 2), new Point($in_w - 2, 0), $black);
$draw->line(new Point(0, $in_h-2), new Point($in_w-2, 0), $black); $draw->line(new Point(1, $in_h - 1), new Point($in_w - 1, 1), $white);
$draw->line(new Point(1, $in_h-1), new Point($in_w-1, 1), $white);
$fsize = MAX(8, (int)(MAX($in_w, $in_h)/30)); $fsize = max(8, (int) (max($in_w, $in_h) / 30));
$fonts = array( $fonts = array(
$imagine->font(__DIR__ . '/arial.ttf', $fsize, $black), $imagine->font(__DIR__ . '/arial.ttf', $fsize, $black),
$imagine->font(__DIR__ . '/arial.ttf', $fsize, $white) $imagine->font(__DIR__ . '/arial.ttf', $fsize, $white)
); );
$testbox = $fonts[0]->box($collname, 0); $testbox = $fonts[0]->box($collname, 0);
$tx_w = MIN($in_w, $testbox->getWidth()); $tx_w = min($in_w, $testbox->getWidth());
$tx_h = MIN($in_h, $testbox->getHeight()); $tx_h = min($in_h, $testbox->getHeight());
$x0 = MAX(1, ($in_w-$tx_w)>>1); $x0 = max(1, ($in_w - $tx_w) >> 1);
$y0 = MAX(1, ($in_h-$tx_h)>>1); $y0 = max(1, ($in_h - $tx_h) >> 1);
for($i=0; $i<=1; $i++) { for ($i = 0; $i <= 1; $i++) {
$x = MAX(1, ($in_w>>2) - ($tx_w>>1)); $x = max(1, ($in_w >> 2) - ($tx_w >> 1));
$draw->text($collname, $fonts[$i], new Point($x-$i, $y0-$i), 0); $draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i), 0);
$x = MAX(1, $in_w-$x-$tx_w); $x = max(1, $in_w - $x - $tx_w);
$draw->text($collname, $fonts[$i], new Point($x-$i, $y0-$i), 0); $draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i), 0);
$y = MAX(1, ($in_h>>2) - ($tx_h>>1)); $y = max(1, ($in_h >> 2) - ($tx_h >> 1));
$draw->text($collname, $fonts[$i], new Point($x0-$i, $y-$i), 0); $draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i), 0);
$y = MAX(1, $in_h-$y-$tx_h); $y = max(1, $in_h - $y - $tx_h);
$draw->text($collname, $fonts[$i], new Point($x0-$i, $y-$i), 0); $draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i), 0);
} }
} }
$in_image->save($pathOut); $in_image->save($pathOut);