Пример #1
0
 public function Format($row, $fieldname, $value)
 {
     $files = $this->_context->getUploadFileNames();
     if ($files[$fieldname] != "") {
         $fileProcessor = new UploadFilenameProcessor($this->_saveAs);
         $fileProcessor->setFilenameLocation(ForceFilenameLocation::DefinePath, FileUtil::GetTempDir());
         // Save the files in a temporary directory
         $result = $this->_context->processUpload($fileProcessor, false, $fieldname);
         // Get a way to rename the files
         $fileinfo = pathinfo($result[0]);
         if ($this->_saveAs != "*") {
             $path_parts = pathinfo($this->_saveAs);
         } else {
             $path_parts = pathinfo($result[0]);
         }
         $newName = $this->_path . FileUtil::Slash() . $path_parts['filename'] . "." . $fileinfo["extension"];
         // Put the image in the right place
         if (strpos(".jpg.gif.jpeg.png", "." . $fileinfo["extension"]) === false) {
             rename($result[0], $newName);
         } else {
             if ($this->_width > 0 || $this->_height > 0) {
                 $image = new ImageUtil($result[0]);
                 $image->resizeAspectRatio($this->_width, $this->_height, 255, 255, 255)->save($newName);
             } else {
                 rename($result[0], $newName);
             }
         }
         return $newName;
     } else {
         return $row->getField($fieldname);
     }
 }
Пример #2
0
 /**
  * @covers ByJG\ImageUtil\ImageUtil::restore
  * @todo   Implement testRestore().
  */
 public function testRestore()
 {
     $expected = $this->getResourceString($this->object->getImage());
     // Do some operactions
     $this->object->rotate(30);
     $this->object->flip(Flip::BOTH);
     $this->object->resizeSquare(40);
     $this->assertNotEquals($expected, $this->getResourceString($this->object->getImage()));
     $this->object->restore();
     $this->assertEquals($expected, $this->getResourceString($this->object->getImage()));
 }
Пример #3
0
 /**
  * Stamp an image in the current image.
  *
  * @param ImageUtil|string $srcImage The image path or the image gd resource.
  * @param int $position
  * @param int $padding
  * @param int $oppacity
  * @return ImageUtil
  * @throws ImageUtilException
  */
 public function stampImage($srcImage, $position = StampPosition::BOTTOMRIGHT, $padding = 5, $oppacity = 100)
 {
     $dstImage = $this->image;
     if ($srcImage instanceof ImageUtil) {
         $imageUtil = $srcImage;
     } else {
         $imageUtil = new ImageUtil($srcImage);
     }
     $watermark = $imageUtil->getImage();
     imagealphablending($dstImage, true);
     imagealphablending($watermark, true);
     $dstWidth = imagesx($dstImage);
     $dstHeight = imagesy($dstImage);
     $srcWIdth = imagesx($watermark);
     $srcHeight = imagesy($watermark);
     if (is_array($padding)) {
         $padx = $padding[0];
         $pady = $padding[1];
     } else {
         $padx = $pady = $padding;
     }
     if ($position == StampPosition::RANDOM) {
         $position = rand(1, 9);
     }
     switch ($position) {
         case StampPosition::TOPRIGHT:
             $dstX = $dstWidth - $srcWIdth - $padx;
             $dstY = $pady;
             break;
         case StampPosition::TOPLEFT:
             $dstX = $padx;
             $dstY = $pady;
             break;
         case StampPosition::BOTTOMRIGHT:
             $dstX = $dstWidth - $srcWIdth - $padx;
             $dstY = $dstHeight - $srcHeight - $pady;
             break;
         case StampPosition::BOTTOMLEFT:
             $dstX = $padx;
             $dstY = $dstHeight - $srcHeight - $pady;
             break;
         case StampPosition::CENTER:
             $dstX = $dstWidth / 2 - $srcWIdth / 2;
             $dstY = $dstHeight / 2 - $srcHeight / 2;
             break;
         case StampPosition::TOP:
             $dstX = $dstWidth / 2 - $srcWIdth / 2;
             $dstY = $pady;
             break;
         case StampPosition::BOTTOM:
             $dstX = $dstWidth / 2 - $srcWIdth / 2;
             $dstY = $dstHeight - $srcHeight - $pady;
             break;
         case StampPosition::LEFT:
             $dstX = $padx;
             $dstY = $dstHeight / 2 - $srcHeight / 2;
             break;
         case StampPosition::RIGHT:
             $dstX = $dstWidth - $srcWIdth - $padx;
             $dstY = $dstHeight / 2 - $srcHeight / 2;
             break;
         default:
             throw new ImageUtilException('Invalid Stamp Position');
     }
     imagecopymerge($dstImage, $watermark, $dstX, $dstY, 0, 0, $srcWIdth, $srcHeight, $oppacity);
     $this->image = $dstImage;
     return $this;
 }
Пример #4
0
<?php

use ByJG\ImageUtil\ImageUtil;
require 'vendor/autoload.php';
$resourceImg = imagecreatetruecolor(200, 300);
$img = new ImageUtil($resourceImg);
$img->save('/tmp/resource.png');
$img = new ImageUtil('/tmp/resource.png');
$img->resize(500, 400);
$img->save('/tmp/resource2.png');
// From an URL
$img2 = new ImageUtil('https://raw.github.com/byjg/xmlnuke/master/xmlnuke-common/imgs/logo_xmlnuke.gif');
$img2->rotate(45);
$img2->save('/tmp/resource3.png');
// From an existing resource image