public function run(File $file) { $image = $this->intervention->make($file->getRealPath()); $image->orientate(); $image->save(null, 100); $image->destroy(); }
public function process(File $file, Image $image) { $imageData = $this->intervention->make($file->getRealPath()); $imageData->brightness($this->brightness); $imageData->blur($this->blur); $imageData->save(null, $this->compression); }
/** * * @param string $uid * * @return StreamedResponse|RedirectResponse */ public function downloadAction($uid) { $urlFrom = $this->getReferer(); if (null == $urlFrom || trim($urlFrom) == '') { $urlFrom = $this->generateUrl('_info_homepage'); } $em = $this->getEntityManager(); try { $biDoc = $em->getRepository('AcfDataBundle:BiDoc')->find($uid); if (null == $biDoc) { $logger = $this->getLogger(); $logger->addError('Document inconnu'); $this->flashMsgSession('warning', $this->translate('BiDoc.download.notfound')); } else { $biDocDir = $this->getParameter('kernel.root_dir') . '/../web/res/biDocs'; $fileName = $biDoc->getFileName(); try { $dlFile = new File($biDocDir . '/' . $fileName); $response = new StreamedResponse(function () use($dlFile) { $handle = fopen($dlFile->getRealPath(), 'r'); while (!feof($handle)) { $buffer = fread($handle, 1024); echo $buffer; flush(); } fclose($handle); }); $timestamp = $biDoc->getDtUpdate()->getTimestamp(); $response->headers->set('Content-Type', $biDoc->getMimeType()); $response->headers->set('Cache-Control', ''); $response->headers->set('Content-Length', $biDoc->getSize()); $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $timestamp)); $fallback = $this->normalize($biDoc->getTitle()); $contentDisposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $biDoc->getOriginalName(), $fallback); $response->headers->set('Content-Disposition', $contentDisposition); $biDoc->setNbrDownloads($biDoc->getNbrDownloads() + 1); $em->persist($biDoc); $em->flush(); return $response; } catch (FileNotFoundException $fnfex) { $logger = $this->getLogger(); $logger->addError('Fichier introuvable ou autre erreur'); $logger->addError($fnfex->getMessage()); $this->flashMsgSession('error', $fnfex->getMessage()); $this->flashMsgSession('warning', $this->translate('BiDoc.download.notfound')); } } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); $this->flashMsgSession('error', $e->getMessage()); $this->flashMsgSession('warning', $this->translate('BiDoc.download.notfound')); } return $this->redirect($urlFrom); }
/** * @param File $file * @param Administration $administration * @return array * * @throws InvalidBankAccountException * @throws InvalidCurrencyException */ public function import(File $file, Administration $administration) { $return = array(); if (($handle = fopen($file->getRealPath(), "r")) !== FALSE) { while (($row = fgetcsv($handle)) !== FALSE) { $return[] = $this->createTransactionFromRow($row, $administration); } fclose($handle); } return $return; }
public function process(File $file, Image $image, array $config = null) { $imageData = Intervention::make($file->getRealPath()); $preserveRatio = $this->preserveRatio; $imageData->resize($this->width, $this->height, function ($constraint) use($preserveRatio) { if ($preserveRatio) { $constraint->aspectRatio(); } }); $imageData->save(null, 100); }
public function process(File $file, Image $image, array $config = null) { $imageData = Intervention::make($file->getRealPath()); // Sections override origin data. if ($this->section) { // ToDo: Add parameter to calculate crops by section. return; } else { $imageData->crop($this->width, $this->height, $this->originTop, $this->originLeft); } $imageData->save(null, 100); }
public function run(File $file) { $image = $this->intervention->make($file->getRealPath()); $preserveRatio = $this->preserveRatio; $image->resize($this->width, $this->height, function ($constraint) use($preserveRatio) { if ($preserveRatio) { $constraint->aspectRatio(); } }); $image->save(null, 100); $image->destroy(); }
/** * Creates a file object from a file on the disk. */ public function fromFile($filePath) { if ($filePath === null) { return; } $file = new FileObj($filePath); $this->file_name = $file->getFilename(); $this->file_size = $file->getSize(); $this->content_type = $file->getMimeType(); $this->disk_name = $this->getDiskName(); $this->putFile($file->getRealPath(), $this->disk_name); return $this; }
/** * @param File|null $image * @param $image_type * @return \Imagine\Image\ImageInterface */ public function getImageThumb(File $image = null, $image_type, $image_area = null) { if (isset($this->image_types[$image_type])) { $source = $this->imagine->open($image->getRealPath()); $this->preProcessSourceImg($source); $this->preProcessCropArea($source, $image_area); $type = $this->image_types[$image_type]; $transformer_class = self::TRANSFORMER_CLASS_PATH . "\\" . Inflector::classify($type['transform']) . 'Transformer'; $width = isset($type['width']) ? $type['width'] : null; $height = isset($type['height']) ? $type['height'] : null; /** @var $transformer TransformerInterface */ $transformer = new $transformer_class($this->imagine, $source, $width, $height); $retval = $transformer->getTransformed(); } else { throw new ResourceNotFoundException("Can't show image!"); } return $retval->strip(); }
function it_is_configurable(File $file) { $file->getRealPath()->willReturn('/path/to/file/img.jpg'); $this->getFilePath()->shouldReturn(null); $this->isMultiple()->shouldReturn(false); $this->getCodeField()->shouldReturn('code'); $this->isUploadAllowed()->shouldReturn(false); $this->setFilePath('/path/to/file/'); $this->setMultiple(true); $this->setCodeField('custom_code'); $this->setUploadAllowed(true); $this->getFilePath()->shouldReturn('/path/to/file/'); $this->isMultiple()->shouldReturn(true); $this->getCodeField()->shouldReturn('custom_code'); $this->isUploadAllowed()->shouldReturn(true); $this->setUploadedFile($file); $this->getFilePath()->shouldReturn('/path/to/file/img.jpg'); }
/** * Enregistre l'icône sur le disque. * * @return void */ protected function uploadImage() { $this->deleteImage(); $this->miniature = null; $fichier = new Fichier($this->imageFile->getRealPath()); $this->image = $this->imageFile->getClientOriginalName(); $this->dossier = $this->guessSousDossier(); $fichier->move($this->getImageUploadDir() . DIRECTORY_SEPARATOR . $this->image, false); $image = new Image($fichier->getChemin()); $image->setNomMinifie($this->getTitle(), '-', true, 128); $this->image = $image->getNom(); if ($image->getLargeur() >= $image->getHauteur() && $image->getLargeur() > $this->getLargeurMaximale()) { $image->redimensionne($this->getLargeurMaximale(), null, true); } elseif ($image->getLargeur() < $image->getHauteur() && $image->getHauteur() > $this->getHauteurMaximale()) { $image->redimensionne(null, $this->getHauteurMaximale(), true); } $this->largeur = $image->getLargeur(); $this->hauteur = $image->getHauteur(); $this->setImageFile(null); }
public function fromFile($src, $target_quality = 90) { $imageFileName = strtok(str_replace(appHomeUrl() . '/storage/app/tmp/', '', $src), '?'); if (startWith($imageFileName, self::getPrefix())) { $file = new File(storage_path('app/tmp/' . $imageFileName)); if ($file) { $this->targetFileAsset = asset('storage/app/tmp/' . $imageFileName); $this->imageType = $file->getMimeType(); $this->imageFilePath = $file->getRealPath(); switch (strtolower($this->imageType)) { case 'image/png': $this->imageFileExt = 'png'; $this->image = imagecreatefrompng($this->imageFilePath); break; case 'image/gif': $this->imageFileExt = 'gif'; $this->image = imagecreatefromgif($this->imageFilePath); break; case 'image/jpeg': case 'image/pjpeg': $this->imageFileExt = 'jpg'; $this->image = imagecreatefromjpeg($this->imageFilePath); break; default: $this->saveResult(['success' => false, 'message' => 'Image type was not supported']); return false; } $this->imageFileSize = $file->getSize(); $this->targetQuality = $target_quality; list($imageWidth, $imageHeight) = getimagesize($this->imageFilePath); $this->imageWidth = $imageWidth; $this->imageHeight = $imageHeight; $this->targetFileName = $imageFileName; $this->targetFilePath = $this->imageFilePath; return true; } } $this->saveResult(['success' => false, 'message' => 'Image was not existed']); return false; }
/** * imageResize * * @param File $file * @param int $maxWidth * @param int $maxHeight * @param bool $enlarge * @param bool $keepRatio * * @return ImageInterface|File|static */ protected function imageResize(File $file, $maxWidth, $maxHeight, $enlarge = false, $keepRatio = true) { if ($maxWidth == 0 && $maxHeight == 0) { return $file; } elseif ($maxHeight == 0) { $maxHeight = $maxWidth; } elseif ($maxWidth == 0) { $maxWidth = $maxHeight; } $imagine = new Imagine(); $resizeImg = $imagine->open($file->getRealPath()); //get the size of the image you're resizing. $origHeight = $resizeImg->getSize()->getHeight(); $origWidth = $resizeImg->getSize()->getWidth(); if ($keepRatio) { //check for longest side, we'll be seeing that to the max value above if ($origHeight > $origWidth) { $newWidth = $maxHeight * $origWidth / $origHeight; $newHeight = $maxHeight; } else { $newHeight = $maxWidth * $origHeight / $origWidth; $newWidth = $maxWidth; } } else { $newWidth = $maxWidth; $newHeight = $maxHeight; } //dont enlarge small images if (!$enlarge) { if ($origHeight > $origWidth && $newHeight > $origHeight || $newWidth > $origWidth) { return $file; } } $size = new Box($newWidth, $newHeight); $resizeImg->resize($size)->save($file->getRealPath()); return $file; }
public function __construct(File $file, FFMpeg $ffmpeg) { $this->video = $ffmpeg->open($file->getRealPath()); }
/** * Create the database entry for an image. * * @param File $image * @param array $attributes * @return Image */ protected function createImageRecord(File $image, array $attributes = []) { // Obtain image metadata and save the record to the database. $imageData = new ImageData($image, $this->intervention->make($image->getRealPath())); $attributes = array_merge($attributes, ['width' => $imageData->getWidth(), 'height' => $imageData->getHeight(), 'average_color' => $imageData->getAveragePixelColor(), 'mime_type' => $image->getMimeType()]); return $this->imageRepository->create($attributes); }
public function __construct(File $file) { $this->image = Image::make($file->getRealPath()); }
public function it_has_file_upload_capability(File $file) { $file->getRealPath()->willReturn('file_path'); $this->setUploadedFile($file); $this->getFilePath()->shouldReturn('file_path'); }
/** * @param File $file * * @return Tag */ public function readFile(File $file) { $this->setBinaryReader(new BinaryReader(fopen($file->getRealPath(), 'rb+'))); return $this->readTag(); }
public function setWatermark($full_path) { $file = new File($full_path); $this->watermark = $this->imagine->open($file->getRealPath()); }
/** * @param File $file * * @return string */ protected function uploadFile(File $file) { $name = $file->getFilename(); $path = $this->getUniqueFilePath($name); $this->getDisk()->put($path, file_get_contents($file->getRealPath()), $this->visibility); return $path; }
/** * Load from input file. * * @param UploadedFile $file */ public function loadFile($input) { //Select correct path based on input if (array_key_exists('file', $input)) { $path = $input['file']->getRealPath(); } elseif (array_key_exists('path', $input)) { $file = new File($input['path']); $path = $file->getRealPath(); } $binder = new MIValueBinder(); $this->loaded_data = $this->file_importer->setValueBinder($binder)->load($path, $this->encoding); }
/** * Generate Thumbnail images with ImageMagick. * * @param string $imageData Image Data * @param int $height Height value * @param int $width Width value * @param int $type Type * * @return string Resized image data * * @throws \RuntimeException */ public function resize($imageData, $height, $width, $type = ElcodiMediaImageResizeTypes::FORCE_MEASURES) { if (ElcodiMediaImageResizeTypes::NO_RESIZE === $type) { return $imageData; } $originalFile = new File(tempnam(sys_get_temp_dir(), '_original')); $resizedFile = new File(tempnam(sys_get_temp_dir(), '_resize')); file_put_contents($originalFile, $imageData); //ImageMagick params $pb = new ProcessBuilder(); $pb->add($this->imageConverterBin)->add($originalFile->getPathname())->add('-profile')->add($this->profile); //Lanczos filter for reduction $pb->add('-filter')->add('Lanczos'); if ($width == 0) { $width = ''; } if ($height == 0) { $height = ''; } /** * Apply some filters depending on type of resizing. */ if ($width || $height) { $pb->add('-resize'); switch ($type) { case ElcodiMediaImageResizeTypes::INSET: $pb->add($width . 'x' . $height); break; case ElcodiMediaImageResizeTypes::INSET_FILL_WHITE: $pb->add($width . 'x' . $height)->add('-gravity')->add('center')->add('-extent')->add($width . 'x' . $height); break; case ElcodiMediaImageResizeTypes::OUTBOUNDS_FILL_WHITE: $pb->add($width . 'x' . $height . ''); break; case ElcodiMediaImageResizeTypes::OUTBOUND_CROP: $pb->add($width . 'x' . $height . '^')->add('-gravity')->add('center')->add('-crop')->add($width . 'x' . $height . '+0+0'); break; case ElcodiMediaImageResizeTypes::FORCE_MEASURES: default: $pb->add($width . 'x' . $height . '!'); break; } } $proc = $pb->add($resizedFile->getPathname())->getProcess(); $proc->run(); if (false !== strpos($proc->getOutput(), 'ERROR')) { throw new \RuntimeException($proc->getOutput()); } $imageContent = file_get_contents($resizedFile->getRealPath()); unlink($originalFile); unlink($resizedFile); return $imageContent; }
public function process(File $file, Image $image, array $config = null) { $imageData = Intervention::make($file->getRealPath()); $imageData->orientate(); $imageData->save(null, 100); }
/** * Saves a file. * * Exceptions can provide extended error information and will abort the save process. * * @param File $file * @param FileModel $fileModel * @param array $options */ public function saveFile(File $file, FileModel $fileModel, array $options = []) { // Upload a file. $this->s3->putObject(array('Bucket' => $this->awsBucket, 'Key' => $this->nameGenerator->fileName($fileModel, $options), 'SourceFile' => $file->getRealPath(), 'ACL' => CannedAcl::PRIVATE_ACCESS)); }
public function saveFile(File $file, Image $image, array $filters = []) { $this->ftp->put($this->root . '/' . $this->generateFileName($image, $filters), $file->getRealPath()); }
/** * Set uploaded file * * @param File $uploadedFile * * @return CsvReader */ public function setUploadedFile(File $uploadedFile) { $this->filePath = $uploadedFile->getRealPath(); $this->csv = null; return $this; }
/** * @param string|array $location * @param File $file * @param array $extraData * @param array $options * * @return $this * * @throws ValidationException * @throws Exception */ public function uploadBulk($location, File $file, $extraData = [], $options = []) { try { $this->call('POST', $this->buildUri($location, ['bulk' => true, 'upload' => true]), ['content' => base64_encode(file_get_contents($file->getRealPath())), 'type' => $this->getContentTypeByExtension($file->guessExtension()), 'filename' => $file->getFilename()] + $extraData, $options); } catch (Exception $e) { $this->throwSdkException($e); } return $this; }
/** * Upload file to FTP * * If file already exists, we do nothing, as it's assumed that files have * unique filenames, and an identical name would mean that the file is * identical to the one already uploaded. * * @param \Symfony\Component\HttpFoundation\File\File $originFile * @param $targetFile * @throws Exception\UploadException * @return string */ public function putByName(File $originFile, $targetFile) { $publicUrl = $this->publicUrl . $targetFile; $tmpDestination = '/' . $this->tmpFolder . $targetFile; $publicDestination = '/' . $this->publicFolder . $targetFile; $this->ftp->preparePaths(array($tmpDestination, $publicDestination)); $alreadyUploaded = $this->ftp->checkIfAlreadyUploaded($originFile->getSize(), $publicDestination, $tmpDestination); if ($alreadyUploaded) { return $publicUrl; } $result = $this->ftp->put($tmpDestination, $originFile->getRealPath()); if ($result) { $this->logger->info('FTP PUT succeeded.'); try { $this->ftp->verifyAndMoveUploadedFile($originFile->getSize(), $tmpDestination, $publicDestination); } catch (FtpException $e) { $this->logger->error($e->getMessage()); throw new UploadException('Error verifying uploaded file.'); } $this->logger->warning('Skipping verification of public url: ' . $publicUrl); } else { $this->logger->error('Error uploading to temp'); throw new UploadException('Error uploading file to storage.'); } return $publicUrl; }
/** * {@inheritdoc} */ public function prepare(Request $request) { $this->headers->set('Content-Length', $this->file->getSize()); if (!$this->headers->has('Accept-Ranges')) { // Only accept ranges on safe HTTP methods $this->headers->set('Accept-Ranges', $request->isMethodSafe() ? 'bytes' : 'none'); } if (!$this->headers->has('Content-Type')) { $this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream'); } if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) { $this->setProtocolVersion('1.1'); } $this->ensureIEOverSSLCompatibility($request); $this->offset = 0; $this->maxlen = -1; if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) { // Use X-Sendfile, do not send any content. $type = $request->headers->get('X-Sendfile-Type'); $path = $this->file->getRealPath(); // Fall back to scheme://path for stream wrapped locations. if (false === $path) { $path = $this->file->getPathname(); } if (strtolower($type) === 'x-accel-redirect') { // Do X-Accel-Mapping substitutions. // @link http://wiki.nginx.org/X-accel#X-Accel-Redirect foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) { $mapping = explode('=', $mapping, 2); if (2 === count($mapping)) { $pathPrefix = trim($mapping[0]); $location = trim($mapping[1]); if (substr($path, 0, strlen($pathPrefix)) === $pathPrefix) { $path = $location . substr($path, strlen($pathPrefix)); break; } } } } $this->headers->set($type, $path); $this->maxlen = 0; } elseif ($request->headers->has('Range')) { // Process the range headers. if (!$request->headers->has('If-Range') || $this->hasValidIfRangeHeader($request->headers->get('If-Range'))) { $range = $request->headers->get('Range'); $fileSize = $this->file->getSize(); list($start, $end) = explode('-', substr($range, 6), 2) + array(0); $end = '' === $end ? $fileSize - 1 : (int) $end; if ('' === $start) { $start = $fileSize - $end; $end = $fileSize - 1; } else { $start = (int) $start; } if ($start <= $end) { if ($start < 0 || $end > $fileSize - 1) { $this->setStatusCode(416); } elseif ($start !== 0 || $end !== $fileSize - 1) { $this->maxlen = $end < $fileSize ? $end - $start + 1 : -1; $this->offset = $start; $this->setStatusCode(206); $this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize)); $this->headers->set('Content-Length', $end - $start + 1); } } } } return $this; }
public function process(File $file, Image $image, array $config = null) { $imageData = Intervention::make($file->getRealPath()); $imageData->fit($this->width, $this->height); $imageData->save(null, 100); }