Esempio n. 1
1
 /**
  * Function that gets called on a job
  * Push::queue('smsSender', $emergency);
  *
  * @param $job
  * @param Emergency $emergency
  */
 public function fire($job, $image)
 {
     $s3 = AWS::get('s3');
     $image = Image::find($image['id']);
     if (!$image) {
         return $job->delete();
     }
     try {
         $imageUtil = new ImageUtil($image->origin);
         $galleryImageUtil = new ImageUtil($image->origin);
     } catch (Exception $e) {
         return $job->delete();
     }
     $image->thumbnail = $this->uploadImage($s3, $imageUtil->resize2('thumbnail')->getImage());
     Log::debug("From queue: Thumbnail: width - {$imageUtil->getWidth()}, height - {$imageUtil->getHeight()}");
     Log::debug("Thumbnail URL: {$image->thumbnail}");
     $this->preventMemoryLeak();
     $image->regular = $this->uploadImage($s3, $galleryImageUtil->resize2('gallery')->getImage());
     Log::debug("From queue: Gallery: width - {$galleryImageUtil->getWidth()}, height - {$galleryImageUtil->getHeight()}");
     Log::debug("Gallery URL: {$image->regular}");
     $this->preventMemoryLeak();
     $image->width = $galleryImageUtil->getWidth();
     $image->height = $galleryImageUtil->getHeight();
     $image->save();
     return $job->delete();
 }
Esempio n. 2
0
 public function upload()
 {
     if (!Input::hasFile('image')) {
         return $this->respondNotFound('Image not found');
     }
     $this->log('Started');
     $this->log(memory_get_usage(true));
     $attachment = new Image();
     $this->file = Input::file('image');
     $this->log('Init origin image');
     $image = new ImageUtil($this->file);
     $this->log(memory_get_usage(true));
     $this->log('Uploading origin image');
     $this->log(memory_get_usage(true));
     $attachment->origin = $this->uploadImage2($image->getImage());
     $this->log(memory_get_usage(true));
     //		preventMemoryLeak();
     $this->log('Garbage collector');
     $this->log(memory_get_usage(true));
     $this->log('Gallery image upload');
     $attachment->regular = $this->uploadImage2($image->resize2('gallery')->getImage());
     $this->log(memory_get_usage(true));
     $this->log('Destroying gallery image');
     $image->getImage()->destroy();
     $image = null;
     $this->log(memory_get_usage(true));
     //		preventMemoryLeak();
     $this->log('Garbage collector');
     $this->log(memory_get_usage(true));
     $this->log('Init thumbnail image');
     $thumb = new ImageUtil($this->file);
     $thumb->resize2('thumbnail');
     $this->log(memory_get_usage(true));
     $this->log('uploading thumbnail image');
     $attachment->thumbnail = $this->uploadImage2($thumb->getImage());
     $this->log(memory_get_usage(true));
     //		preventMemoryLeak();
     $this->log('Garbage collector');
     $this->log(memory_get_usage(true));
     $attachment->width = $thumb->getWidth();
     $attachment->height = $thumb->getHeight();
     $this->log('Destroying the thumb image');
     $thumb->getImage()->destroy();
     $thumb = null;
     $this->log(memory_get_usage(true));
     $attachment->save();
     return $this->respond($this->collectionTransformer->transformImage($attachment));
 }
Esempio n. 3
0
 public function setAvatar($img)
 {
     $s3 = AWS::get('s3');
     $thumbnailPlaceholder = S3_PUBLIC . 'placeholder_128.png';
     $profilePlaceholder = S3_PUBLIC . 'placeholder_64.png';
     $imageUtil = new ImageUtil($img);
     $this->img_origin = $this->uploadImage($s3, $imageUtil->getImage());
     $imageUtil->getImage()->destroy();
     $imageUtil = null;
     preventMemoryLeak();
     $imageUtil2 = new ImageUtil($img);
     $this->img_large = $this->uploadImage($s3, $imageUtil2->resize2('avatar.gallery')->getImage());
     $imageUtil2->getImage()->destroy();
     $imageUtil = null;
     preventMemoryLeak();
     $imageUtil3 = new ImageUtil($img);
     $this->img_middle = $this->uploadImage($s3, $imageUtil3->resize2('avatar.profile')->getImage()) ?: $profilePlaceholder;
     $imageUtil3->getImage()->destroy();
     $imageUtil3 = null;
     preventMemoryLeak();
     $imageUtil4 = new ImageUtil($img);
     $this->img_small = $this->uploadImage($s3, $imageUtil4->resize2('avatar.thumbnail')->getImage()) ?: $thumbnailPlaceholder;
     $imageUtil4->getImage()->destroy();
     $imageUtil4 = null;
     preventMemoryLeak();
 }
 public function attach($id)
 {
     $chat = CarChat::find($id);
     if (!$chat) {
         return $this->respondNotFound();
     }
     if (!$chat->isMember($this->user->id)) {
         return $this->respondInsufficientPrivileges('User is not the member of chat');
     }
     if (!Input::hasFile('image')) {
         return $this->respondInsufficientPrivileges('No image');
     }
     $file = Input::file('image');
     if (!in_array($file->guessExtension(), ['png', 'gif', 'jpeg', 'jpg'])) {
         return $this->respondInsufficientPrivileges('Unsupported file extension');
     }
     $attachment = new MessageAttachment();
     $attachment->id = DB::select("select nextval('messages_attachments_id_seq')")[0]->nextval;
     $this->log('Init images');
     $this->log(memory_get_usage(true));
     $origin = new ImageUtil($file);
     $attachment->origin = $this->upload($attachment->id, 'origin', $origin->getImage());
     $attachment->gallery = $this->upload($attachment->id, 'gallery', $origin->resize2('gallery')->getImage());
     $origin->getImage()->destroy();
     $origin = null;
     $this->log('Images should be destroyed');
     $this->log(memory_get_usage(true));
     $this->log('Init thumbnail');
     $thumb = (new ImageUtil($file))->resize2('thumbnail');
     $attachment->thumb = $this->upload($attachment->id, 'thumb', $thumb->getImage());
     $attachment->width = $thumb->getWidth();
     $attachment->height = $thumb->getHeight();
     $thumb->getImage()->destroy();
     $thumb = null;
     $this->log('Thumbnail should be destroyed');
     $this->log(memory_get_usage(true));
     if ($chat->attachments()->save($attachment)) {
         $domain = 'http' . (Request::server('HTTPS') ? '' : 's') . '://' . Request::server('HTTP_HOST');
         return $this->respond(['id' => $attachment->id, 'thumb' => $domain . '/api/carchats/' . $chat->id . '/attachments/' . $attachment->id, 'origin' => $domain . '/api/carchats/' . $chat->id . '/attachments/' . $attachment->id . '/gallery', 'width' => $attachment->width, 'height' => $attachment->height]);
     }
     $this->log(memory_get_usage(true));
     return $this->respondServerError();
 }
Esempio n. 5
0
 /**
  * Attach a image to chating
  *
  * @return Response
  */
 public function attach()
 {
     $chatId = (int) Input::get('chat_id');
     if ((int) $chatId > 0 && !is_null($chat = Chat::find((int) $chatId)) && $chat->hasMember(Auth::user()->id)) {
         if (Input::hasFile('image')) {
             $file = Input::file('image');
             if (in_array(strtolower($file->guessExtension()), array('png', 'gif', 'jpeg', 'jpg'))) {
                 $attachment = new MessageAttachment();
                 $attachment->chat_id = $chat->id;
                 $attachment->origin = '';
                 $attachment->thumb = '';
                 $attachment->save();
                 $this->log('Init images');
                 $this->log(memory_get_usage(true));
                 $origin = new ImageUtil($file);
                 $attachment->origin = $this->upload($attachment->id, 'origin', $origin->getImage());
                 $attachment->gallery = $this->upload($attachment->id, 'gallery', $origin->resize2('gallery')->getImage());
                 $origin->getImage()->destroy();
                 $origin = null;
                 $this->log('Gallery and origin images should be destroyed');
                 $this->log(memory_get_usage(true));
                 $this->log('Init thumbnail');
                 $thumb = (new ImageUtil($file))->resize2('thumbnail');
                 $this->log(memory_get_usage(true));
                 $this->log('Uploading');
                 $attachment->thumb = $this->upload($attachment->id, 'thumb', $thumb->getImage());
                 $this->log(memory_get_usage(true));
                 $attachment->width = $thumb->getWidth();
                 $attachment->height = $thumb->getHeight();
                 $thumb->getImage()->destroy();
                 $thumb = null;
                 $this->log('Thumbnail destroyed');
                 $this->log(memory_get_usage(true));
                 $attachment->save();
                 $domain = 'http' . (Request::server('HTTPS') ? '' : 's') . '://' . Request::server('HTTP_HOST');
                 return $this->respond(array('id' => (int) $attachment->id, 'thumb' => $domain . '/api/messages/attach/thumb/' . $attachment->id, 'origin' => $domain . '/api/messages/attach/gallery/' . $attachment->id, 'width' => $attachment->width, 'height' => $attachment->height));
             } else {
                 return $this->respondWithError('Image has unsupported extension (sent file extension' . strtolower($file->guessExtension()) . ')');
             }
         } else {
             return $this->respondWithError('Image isn\'t found');
         }
     } else {
         return $this->respondWithError('Chat isn\'t found');
     }
 }