public function setDeepzoom($config)
 {
     $this->deepzoom = DeepzoomFactory::create(['path' => isset($config['destination_path']) ? $config['destination_path'] : config('deepzoom.destination_path'), 'driver' => isset($config['driver']) ? $config['driver'] : config('deepzoom.driver'), 'format' => isset($config['tile_format']) ? $config['tile_format'] : config('deepzoom.tile_format')]);
 }
Example #2
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     // get object
     $object = Object::with('assets', 'assets.type', 'source')->where('object_uid', '=', $this->object_uid)->firstOrFail();
     $this->deepzoom = DeepzoomFactory::create(['path' => public_path('images/' . $object->id), 'driver' => config('harvester.image.driver')]);
     // delete directory if it exists
     if ($this->filesystem->has('images/' . $object->id)) {
         $this->filesystem->deleteDir('images/' . $object->id);
         $this->deleteAssetRecords($object);
     }
     foreach ($object->source as $asset) {
         // load image into memory for this asset
         $img = $this->imageManager->make($asset->source_uri);
         // if object has proper rights
         if ($object->can_zoom == 1 || $object->can_download == 1) {
             // create deepzoom tiles
             if ($object->can_zoom == 1) {
                 // get result back form deepzoom
                 $result = $this->deepzoom->makeTiles($asset->source_uri, 'dzi' . $asset->source_sequence, $asset->source_sequence);
                 foreach ($result['data']['output'] as $key => $value) {
                     $asset_type = AssetType::where('asset_type_name', '=', strtolower($key))->first();
                     if ($asset_type) {
                         $asset_type_id = $asset_type->id;
                         $imgPath = 'images/' . $object->id . '/' . $asset->source_sequence . '/' . basename($value);
                         $this->createAsset($imgPath, $asset_type_id, $object->id, $asset->source_sequence, $asset->id);
                     }
                 }
             }
             foreach ($this->sizes as $type => $width) {
                 $this->generateAsset($img, $object->id, $asset, $type, $width);
             }
             if ($object->can_download == 1) {
                 $this->generateAsset($img, $object->id, $asset, 'original', $img->width(), $img->height());
             }
         }
         // generate the sizes below the protected width
         if ($object->protected_size != null) {
             $protected_size = $this->protected[$object->protected_size];
             $img_width = $img->width();
             $img_height = $img->height();
             $aspect_ratio = $img_width / $img_height;
             foreach ($this->sizes as $type => $width) {
                 if ($width <= $protected_size['width']) {
                     if ($aspect_ratio < 1) {
                         $this->generateAsset($img, $object->id, $asset, $type, $width, $protected_size['height']);
                     } else {
                         $this->generateAsset($img, $object->id, $asset, $type, $width, $protected_size['width']);
                     }
                 }
             }
             // check is aspect ratio is horizontal of vertical
             if ($aspect_ratio < 1) {
                 $this->generateAsset($img, $object->id, $asset, 'protected', $protected_size['width'], $protected_size['height']);
             } else {
                 $this->generateAsset($img, $object->id, $asset, 'protected', $protected_size['height'], $protected_size['width']);
             }
         }
     }
     // touch object updated_at timestamp to record transaction
     $object->touch();
 }