本文整理汇总了PHP中Intervention\Image\Image::mime方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::mime方法的具体用法?PHP Image::mime怎么用?PHP Image::mime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::mime方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle request to convert it to a Response object.
*/
public function handle()
{
try {
if (!$this->request->query->has('image')) {
throw new FileNotFoundException("No valid image path found in URI", 1);
}
$nativePath = $this->configuration->getImagesPath() . '/' . $this->request->query->get('image');
$this->nativeImage = new File($nativePath);
$this->parseQuality();
if ($this->configuration->hasCaching()) {
$cache = new FileCache($this->request, $this->nativeImage, $this->configuration->getCachePath(), $this->logger, $this->quality, $this->configuration->getTtl(), $this->configuration->getGcProbability(), $this->configuration->getUseFileChecksum());
$cache->setDispatcher($this->dispatcher);
/** @var Response response */
$this->response = $cache->getResponse(function (InterventionRequest $interventionRequest) {
return $interventionRequest->processImage();
}, $this);
} else {
$this->processImage();
$this->response = new Response((string) $this->image->encode(null, $this->quality), Response::HTTP_OK, ['Content-Type' => $this->image->mime(), 'Content-Disposition' => 'filename="' . $this->nativeImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
$this->response->setLastModified(new \DateTime('now'));
}
} catch (FileNotFoundException $e) {
$this->response = $this->getNotFoundResponse($e->getMessage());
} catch (\RuntimeException $e) {
$this->response = $this->getBadRequestResponse($e->getMessage());
}
}
示例2: getFormat
public function getFormat(Image $image)
{
$allowed = ['gif' => 'image/gif', 'jpg' => 'image/jpeg', 'pjpg' => 'image/jpeg', 'png' => 'image/png'];
if (array_key_exists($this->fm, $allowed)) {
return $this->fm;
}
if ($format = array_search($image->mime(), $allowed, true)) {
return $format;
}
return 'jpg';
}
示例3: getFormat
/**
* Resolve format.
* @param string $format The format.
* @return string The resolved format.
*/
public function getFormat(Image $image, $format)
{
$allowed = ['image/jpeg' => 'jpg', 'image/png' => 'png', 'image/gif' => 'gif'];
if (in_array($format, $allowed, true)) {
return $format;
}
$mime = $image->mime();
if (isset($allowed[$mime])) {
return $allowed[$mime];
}
return 'jpg';
}
示例4: make
/**
* Save file to database and to our filesystem.
*/
public static function make(Picture $picture, Image $image, $identifier)
{
$file = new self();
$file->picture_id = $picture->id;
$file->identifier = $identifier;
$file->mime = $image->mime();
$file->extension = $image->extension;
$file->width = $image->width();
$file->height = $image->height();
self::checkDirPermission();
$image->save($file->getFilePath());
$file->save();
}
示例5: savePicture
/**
* Save an Picture object to the file system.
* Runs OptimizeFileJob on the file after it is saved.
*
* @param Picture $picture
* @param string $directory One of the *_DIR constants.
* @param string $filename
* @param ImageFile|null $originalImageFile
*
* @throws Exception
* @return ImageFile
*/
public function savePicture(Picture $picture, $directory = self::IMAGE_DIR, $filename = null, ImageFile $originalImageFile = null)
{
if (!$filename) {
$mime = $picture->mime();
if (empty($mime)) {
$mime = 'image/jpeg';
}
$extension = $this->getExtensionForMime($mime);
$filename = $this->generateFilename($extension);
}
$relativePath = $directory . '/' . $filename;
// Save locally
if (!$this->savePictureLocally($picture, $relativePath)) {
throw new Exception('Unable to save file locally.');
}
$imageFile = new ImageFile(['originalImageFileId' => $originalImageFile ? $originalImageFile->getId() : null, 'directory' => $directory, 'filename' => $filename, 'width' => $picture->getWidth(), 'height' => $picture->getHeight(), 'size' => $picture->filesize()]);
$imageFile->save();
// Optimize and copy to remote storage
$this->dispatch(new OptimizeFileJob($imageFile));
return $imageFile;
}
示例6: getInfo
public function getInfo()
{
return ['mime' => $this->image->mime(), 'width' => $this->image->width(), 'height' => $this->image->height(), 'extension' => $this->image->extension, 'filename' => $this->image->filename, 'filesize' => $this->image->filesize()];
}
示例7: guessExtension
/**
* Guess extension .
*
* @param Image $image
* @return string
*/
protected function guessExtension(Image $image)
{
$guesser = ExtensionGuesser::getInstance();
return $guesser->guess($image->mime());
}
示例8: createDatabaseRecord
/**
* Create image record.
*
* @return Image
*/
protected function createDatabaseRecord()
{
return Image::create(['hash' => $this->hash, 'mime_type' => $this->image->mime(), 'uploaded_at' => $this->uploaded_at->timestamp]);
}
示例9: buildAssetFromImage
private function buildAssetFromImage(\Intervention\Image\Image $image, $organization, $name, $type)
{
$mime = $image->mime();
$name = new Name($name);
$guid = Guid::generate();
$asset = Asset::register($name, $guid, $mime, $organization);
$asset->setTitle($name);
if (isset($type)) {
$asset->setType($type);
}
return $asset;
}