/** * Store a newly created resource in storage. * * @return Response */ public function store() { $s3 = AWS::get('s3'); $s3Bucket = 'buildbrighton-bbms'; if (Request::hasFile('image')) { $file = Request::file('image'); $event = Request::get('textevent'); $time = Request::get('time'); $fileData = Image::make($file)->encode('jpg', 80); $date = Carbon::createFromFormat('YmdHis', $event); $folderName = $date->hour . ':' . $date->minute . ':' . $date->second; try { $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '/' . $time . '.jpg'; $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $fileData, 'ACL' => 'public-read', 'ContentType' => 'image/jpg', 'ServerSideEncryption' => 'AES256')); } catch (\Exception $e) { \Log::exception($e); } //Log::debug('Image saved :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename); } if (Request::get('eventend') == 'true') { $event = Request::get('textevent'); $date = Carbon::createFromFormat('YmdHis', $event); $folderName = $date->hour . ':' . $date->minute . ':' . $date->second; $iterator = $s3->getIterator('ListObjects', array('Bucket' => $s3Bucket, 'Prefix' => \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName)); $images = []; $imageDurations = []; foreach ($iterator as $object) { $images[] = 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $object['Key']; $imageDurations[] = 35; } if (count($images) <= 2) { //only two images, probably two bad frames //delete them foreach ($iterator as $object) { Log::debug("Deleting small event image " . $object['Key']); $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]); } return; } $gc = new GifCreator(); $gc->create($images, $imageDurations, 0); $gifBinary = $gc->getGif(); //Delete the individual frames now we have the gif foreach ($iterator as $object) { //Log::debug("Processed gif, deleting frame, ".$object['Key']); $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]); } //Save the gif $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '.gif'; $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $gifBinary, 'ACL' => 'public-read', 'ContentType' => 'image/gif', 'ServerSideEncryption' => 'AES256')); //Log::debug('Event Gif generated :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename); \Slack::to("#cctv")->attach(['image_url' => 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $newFilename, 'color' => 'warning'])->send('Movement detected'); } }
$configuration = json_decode(file_get_contents('config.json')); $recordings_dir = 'recordings'; $durations = array(); if (function_exists('imagegif')) { $data = file_get_contents("php://input"); header('Content-type: application/json'); if ($data != false) { $images = json_decode($data); if (isset($images)) { if (sizeof($images) > 0) { $filename = basename($images[0], '.jpg'); foreach ($images as $image) { array_push($durations, $configuration->animgif_frame_duration); } $gc = new GifCreator(); $gc->create($images, $durations, $configuration->animgif_loop_count); $gifBinary = $gc->getGif(); $gif_filename = $recordings_dir . '/' . $filename . '.gif'; if (file_put_contents($gif_filename, $gifBinary) > 0) { echo '["Successfuly created. <a href=\\"view_gif.php?img=' . $gif_filename . '\\">View</a>"]'; } } } else { echo '["Bad data"]'; } } else { echo '["No data"]'; } } else { echo '["Sorry. Your installation does not support GIF creation."]'; }
public function processFolioImage($aFile, $folder, $aName, $imageInfo) { $ext = self::_getImageExt($aFile['type']); if (empty($ext)) { $this->setMessage(iaLanguage::getf('file_type_error', array('extension' => implode(', ', array_unique(self::$_typesMap))))); return false; } $path = IA_UPLOADS . $folder; $image = ImageWorkshop::initFromPath($aFile['tmp_name']); // save source image $image->save($path, self::SOURCE_PREFIX . $aName . $ext); // process thumbnails for files uploaded in CKEditor and other tools if (empty($imageInfo)) { // apply watermark $image = self::_applyWaterMark($image); $image->save($path, self::_createFilename($aName, $ext)); return true; } // check this is an animated GIF if ('image/gif' == $aFile['type'] && $this->iaCore->get('allow_animated_gifs')) { require_once IA_INCLUDES . 'phpimageworkshop' . IA_DS . 'Core' . IA_DS . 'GifFrameExtractor.php'; $gifPath = $aFile['tmp_name']; if (GifFrameExtractor::isAnimatedGif($gifPath)) { // Extractions of the GIF frames and their durations $gfe = new GifFrameExtractor(); $frames = $gfe->extract($gifPath); // For each frame, we add a watermark and we resize it $retouchedFrames = array(); $thumbFrames = array(); foreach ($frames as $frame) { $frameLayer = ImageWorkshop::initFromResourceVar($frame['image']); $thumbLayer = ImageWorkshop::initFromResourceVar($frame['image']); $frameLayer->resizeInPixel($imageInfo['image_width'], $imageInfo['image_height'], true); $frameLayer = self::_applyWaterMark($frameLayer); $retouchedFrames[] = $frameLayer->getResult(); $thumbLayer->resizeInPixel($imageInfo['thumb_width'], $imageInfo['thumb_height'], true); $thumbFrames[] = $thumbLayer->getResult(); } // Then we re-generate the GIF require_once IA_INCLUDES . 'phpimageworkshop' . IA_DS . 'Core' . IA_DS . 'GifCreator.php'; $gc = new GifCreator(); $gc->create($retouchedFrames, $gfe->getFrameDurations(), 0); file_put_contents($path . self::_createFilename($aName, $ext), $gc->getGif()); $thumbCreator = new GifCreator(); $thumbCreator->create($thumbFrames, $gfe->getFrameDurations(), 0); file_put_contents($path . self::_createFilename($aName, $ext, true), $thumbCreator->getGif()); return self::_createFilename($folder . $aName, $ext, true); } } // save full image $largestSide = $imageInfo['image_width'] > $imageInfo['image_height'] ? $imageInfo['image_width'] : $imageInfo['image_height']; if ($largestSide) { $image->resizeByLargestSideInPixel($largestSide, true); } $image = self::_applyWaterMark($image); $image->save($path, self::_createFilename($aName, $ext)); // generate thumbnail $thumbWidth = $imageInfo['thumb_width'] ? $imageInfo['thumb_width'] : $this->iaCore->get('thumb_w'); $thumbHeight = $imageInfo['thumb_height'] ? $imageInfo['thumb_height'] : $this->iaCore->get('thumb_h'); $positionX = $imageInfo['positionX'] ? $imageInfo['positionX'] : 0; $positionY = $imageInfo['positionY'] ? $imageInfo['positionY'] : 0; $position = $imageInfo['position'] ? $imageInfo['position'] : 'MM'; $resize = $imageInfo['resize'] ? $imageInfo['resize'] : 'before_crop'; $cropWidth = $imageInfo['crop_width'] ? $imageInfo['crop_width'] : ''; $cropHeight = $imageInfo['crop_height'] ? $imageInfo['crop_height'] : ''; if ($thumbWidth || $thumbHeight) { $thumb = ImageWorkshop::initFromPath($aFile['tmp_name']); switch ($imageInfo['resize_mode']) { case self::FIT: $thumb->resizeInPixel($thumbWidth, $thumbHeight, true, 0, 0, 'MM'); break; case self::CROP: $largestSide = $thumbWidth > $thumbHeight ? $thumbWidth : $thumbHeight; if ($this->iaCore->get('portfolio_use_crop')) { if ('after_crop' == $resize) { // $thumb->cropMaximumInPixel(0, 0, 'MM'); $thumb->cropInPixel($cropWidth, $cropHeight, $positionX, $positionY, $position); $thumb->resizeInPixel($thumbWidth, $thumbHeight); } else { $thumb->cropMaximumInPixel(0, 0, 'MM'); $thumb->resizeInPixel($largestSide, $largestSide); $thumb->cropInPixel($thumbWidth, $thumbHeight, $positionX, $positionY, $position); } } else { $thumb->cropMaximumInPixel(0, 0, 'MM'); $thumb->resizeInPixel($largestSide, $largestSide); $thumb->cropInPixel($thumbWidth, $thumbHeight, 0, 0, 'MM'); } } $thumb->save($path, self::_createFilename($aName, $ext, true)); } return self::_createFilename($folder . $aName, $ext, true); }