Beispiel #1
0
 public function image($request)
 {
     if (!$request->request->has('image')) {
         return new Response('Image URI is missing', 400);
     }
     $uri = $request->request->get('image');
     if (!$request->request->has('data')) {
         return new Response('Image transformation data is missing', 400);
     }
     $data = $request->request->get('data');
     if (!$this->ctx['fs']->has($uri)) {
         return new Response("Source image not found ({$uri})", 400);
     }
     $img = WideImage::loadFromString($this->ctx['fs']->read($uri));
     if (Utils::isResourceUrl($uri)) {
         $info = Utils::resurlinfo($uri);
     } else {
         $pathinfo = pathinfo($uri);
         $info = array('name' => $pathinfo['filename'], 'ext' => $pathinfo['extension']);
     }
     $datas = explode(':', $data);
     $left = $datas[0];
     $top = $datas[1];
     $width = $datas[2];
     $height = $datas[3];
     $filename = $info['name'];
     $ext = $info['ext'];
     $img = $this->transform_image($img, $top, $left, $width, $height);
     // generate image set
     $res = $this->generateImageSet($img, $filename, $ext);
     $res = array('status' => 0, 'srcset' => $res['srcset'], 'ratio' => $res['ratio']);
     return $this->json($request, $res, 200);
 }
Beispiel #2
0
 public function image($uri, $x = '0%', $y = '0%', $w = '100%', $h = '100%')
 {
     if (Utils::isURL($uri)) {
         list($image, $extension) = $this->loadFromURL($uri);
         //$this->transform(Utils::nameFromURL($uri), $extension, WideImage::loadFromString($image), $x, $y, $w, $h) :
     } else {
         $imageName = $this->imageName($uri);
         $this->transform($imageName['name'], $imageName['extension'], WideImage::loadFromString($this->fs->read($uri)), $x, $y, $w, $h);
     }
 }
Beispiel #3
0
 /**
  * Resize the original image - we don't want to save massive copies of everything
  * @since Version 3.10.0
  * @param string $imageSource
  * @return void
  */
 public static function ResizeOriginal($imageSource)
 {
     $sizes = getimagesize($imageSource);
     if ($sizes[0] <= Image::MAX_WIDTH && $sizes[1] <= Image::MAX_HEIGHT) {
         return true;
     }
     $image = file_get_contents($imageSource);
     $Image = WideImage::loadFromString($image);
     $size = $Image->resize(Image::MAX_WIDTH, Image::MAX_HEIGHT, "inside");
     file_put_contents($imageSource, $size->asString("jpg", 100));
     if (!file_exists($imageSource)) {
         throw new Exception("Resized image and saved to path, but could not find it after!");
     }
     return true;
 }
Beispiel #4
0
 /**
  * (non-PHPdoc)
  * @see \WideImage\Image#copyNoAlpha()
  */
 public function copyNoAlpha()
 {
     $prev = $this->saveAlpha(false);
     $result = WideImage::loadFromString($this->asString('png'));
     $this->saveAlpha($prev);
     //$result->releaseHandle();
     return $result;
 }
Beispiel #5
0
 /**
  * Create other sizes
  * @since Version 3.10.0
  * @return void
  */
 public static function createOtherSizes()
 {
     $sleep = 2;
     $sleep = false;
     $Database = (new AppCore())->getDatabaseConnection();
     $query = "SELECT i.id,\r\n                square.size AS square, square.source AS square_src, square.width AS square_w, square.height AS square_h,\r\n                large_square.size AS large_square, large_square.source AS large_square_src, large_square.width AS large_square_w, large_square.height AS large_square_h,\r\n                small.size AS small, small.source AS small_src, small.width AS small_w, small.height AS small_h,\r\n                small_320.size AS small_320, small_320.source AS small_320_src, small_320.width AS small_320_w, small_320.height AS small_320_h,\r\n                medium.size AS medium, medium.source AS medium_src, medium.width AS medium_w, medium.height AS medium_h,\r\n                medium_640.size AS medium_640, medium_640.source AS medium_640_src, medium_640.width AS medium_640_w, medium_640.height AS medium_640_h,\r\n                medium_800.size AS medium_800, medium_800.source AS medium_800_src, medium_800.width AS medium_800_w, medium_800.height AS medium_800_h,\r\n                original.size AS original, original.source AS original_src, original.width AS original_w, original.height AS original_h\r\n            FROM gallery_mig_image AS i\r\n                LEFT JOIN gallery_mig_image_sizes AS square ON square.photo_id = i.id AND square.size = 'square'\r\n                LEFT JOIN gallery_mig_image_sizes AS large_square ON large_square.photo_id = i.id AND large_square.size = 'large_square'\r\n                LEFT JOIN gallery_mig_image_sizes AS small ON small.photo_id = i.id AND small.size = 'small'\r\n                LEFT JOIN gallery_mig_image_sizes AS small_320 ON small_320.photo_id = i.id AND small_320.size = 'small_320'\r\n                LEFT JOIN gallery_mig_image_sizes AS medium ON medium.photo_id = i.id AND medium.size = 'medium'\r\n                LEFT JOIN gallery_mig_image_sizes AS medium_640 ON medium_640.photo_id = i.id AND medium_640.size = 'medium_640'\r\n                LEFT JOIN gallery_mig_image_sizes AS medium_800 ON medium_800.photo_id = i.id AND medium_800.size = 'medium_800'\r\n                LEFT JOIN gallery_mig_image_sizes AS original ON original.photo_id = i.id AND original.size = 'original'\r\n            WHERE i.hidden = 0\r\n            AND square.size IS NULL\r\n            AND large_square.size IS NULL\r\n            AND small.size IS NULL\r\n            AND small_320.size IS NULL\r\n            AND medium.size IS NULL\r\n            AND medium_640.size IS NULL\r\n            AND medium_800.size IS NULL\r\n            LIMIT 0, 250";
     $result = $Database->fetchAll($query);
     /**
      * Set our desired sizes
      */
     $sizes = ["square" => ["width" => 75, "height" => 75], "large_square" => ["width" => 150, "height" => 150], "small" => ["width" => 240, "height" => 0], "small_320" => ["width" => 320, "height" => 0], "medium" => ["width" => 500, "height" => 0], "medium_640" => ["width" => 640, "height" => 0], "medium_800" => ["width" => 800, "height" => 0]];
     /** 
      * Loop through the results and start building the sizes
      */
     foreach ($result as $row) {
         /**
          * Load the original image from disk. If it doesn't exist then continue to the next array item
          */
         $filename = sprintf("%s%s", Album::ALBUMS_DIR, $row['original_src']);
         if (!file_exists($filename)) {
             continue;
         }
         $ext = pathinfo($filename, PATHINFO_EXTENSION);
         $allowedtypes = ["jpeg", "jpg", "png", "gif"];
         if (!in_array($ext, $allowedtypes)) {
             continue;
         }
         $noext = str_replace("." . $ext, "", $filename);
         $image = file_get_contents($filename);
         Debug::LogCLI("Source image " . $filename);
         /**
          * Loop through each required size
          */
         foreach ($sizes as $key => $dims) {
             /**
              * If the size already exists in DB then proceed to the next size
              */
             if (!is_null($row[$key]) || $key == "original") {
                 continue;
             }
             /**
              * Break out of the loop if the desired size is larger than than the original image 
              */
             if ($dims['width'] > $row['original_w']) {
                 continue;
             }
             $dstfile = sprintf("%s.%s.%s", $noext, $key, $ext);
             if (file_exists($dstfile)) {
                 unlink($dstfile);
             }
             Debug::LogCLI("  Creating " . $key . " from image " . $filename);
             Debug::LogCLI("");
             $Image = WideImage::loadFromString($image);
             if ($dims['width'] == $dims['height']) {
                 $size = $Image->resize($dims['width'], $dims['height'], "outside");
                 $size = $size->crop(0, "middle", $dims['width'], $dims['height']);
             }
             if ($dims['width'] != $dims['height']) {
                 $size = $Image->resize($dims['width'], $dims['width'], "inside");
             }
             $quality = $dims['width'] <= 240 ? 80 : 100;
             file_put_contents($dstfile, $size->asString("jpg", $quality));
             if (file_exists($dstfile)) {
                 Debug::LogCLI("  Image created, inserting into DB");
                 Debug::LogCLI("  " . $dstfile);
                 $data = ["photo_id" => $row['id'], "size" => $key, "source" => $dstfile, "width" => $size->getWidth(), "height" => $size->getHeight()];
                 $Database->insert("gallery_mig_image_sizes", $data);
             }
             Debug::LogCLI("  ---");
         }
         if ($sleep) {
             Debug::LogCLI("-------------------------------");
             Debug::LogCLI("");
             Debug::LogCLI("Sleeping for two seconds");
             Debug::LogCLI("");
             sleep($sleep);
         }
         Debug::LogCLI("-------------------------------");
         Debug::LogCLI("");
     }
 }
 /**
  * @expectedException WideImage\Exception\InvalidImageSourceException
  */
 public function testInvalidImageStringData()
 {
     WideImage::loadFromString('asdf');
 }
 /**
  * Restores an image from serialization. Called automatically upon unserialize().
  */
 public function __wakeup()
 {
     $temp_image = WideImage::loadFromString($this->sdata);
     $temp_image->releaseHandle();
     $this->handle = $temp_image->handle;
     $temp_image = null;
     $this->sdata = null;
 }
 /**
  * (non-PHPdoc)
  * @see \WideImage\Image#copyNoAlpha()
  */
 public function copyNoAlpha()
 {
     return WideImage::loadFromString($this->asString('png'));
 }