-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add support for JPEG XL image format #41058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
1div0
wants to merge
15
commits into
nextcloud:master
Choose a base branch
from
1div0:JPEG XL
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "JPEG\u00A0XL"
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f5c4c14
Add support for JPEG XL image format
1div0 77bca06
Changed according to review comment
1div0 7b99332
Added JPEG XL MIME type
1div0 9e0839c
Add JPEG XL to MIME type list
1div0 a243d3b
Trying to resolve merge conflicts
1div0 05f6ab9
Merge branch 'master' into JPEG XL
1div0 a61791a
Merge branch 'nextcloud:master' into JPEG XL
1div0 7ac0306
Merge branch 'nextcloud:master' into JPEG XL
1div0 fc5758a
Merge branch 'nextcloud:master' into JPEG XL
1div0 ed60954
Merge branch 'nextcloud:master' into JPEG XL
1div0 da43e1d
Merge branch 'nextcloud:master' into JPEG XL
1div0 3e62c21
Merge branch 'nextcloud:master' into JPEG XL
1div0 f28d8df
Merge branch 'nextcloud:master' into JPEG XL
1div0 49b75b3
Merge branch 'nextcloud:master' into JPEG XL
1div0 c517c27
Merge branch 'nextcloud:master' into JPEG XL
1div0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| <?php | ||
| /** | ||
| * @copyright Copyright (c) 2016, ownCloud, Inc. | ||
| * | ||
| * @author Olivier Paroz <[email protected]> | ||
| * @author Robin Appelman <[email protected]> | ||
| * @author Peter Kovář <[email protected]> | ||
| * | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
| namespace OC\Preview; | ||
|
|
||
| use OCP\Files\File; | ||
| use OCP\Files\FileInfo; | ||
| use OCP\IImage; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| /** | ||
| * Creates a JXL preview using ImageMagick via the PECL extension | ||
| * | ||
| * @package OC\Preview | ||
| */ | ||
| class JXL extends ProviderV2 { | ||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function getMimeType(): string { | ||
| return '/image\/jxl/'; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function isAvailable(FileInfo $file): bool { | ||
| return in_array('JXL', \Imagick::queryFormats("JXL")); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { | ||
| if (!$this->isAvailable($file)) { | ||
| return null; | ||
| } | ||
|
|
||
| $tmpPath = $this->getLocalFile($file); | ||
| if ($tmpPath === false) { | ||
| \OC::$server->get(LoggerInterface::class)->error( | ||
| 'Failed to get thumbnail for: ' . $file->getPath(), | ||
| ['app' => 'core'] | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| // Creates \Imagick object from the heic file | ||
| try { | ||
| $bp = $this->getResizedPreview($tmpPath, $maxX, $maxY); | ||
| $bp->setFormat('jxl'); | ||
| } catch (\Exception $e) { | ||
| \OC::$server->get(LoggerInterface::class)->error( | ||
| 'File: ' . $file->getPath() . ' Imagick says:', | ||
| [ | ||
| 'exception' => $e, | ||
| 'app' => 'core', | ||
| ] | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| $this->cleanTmpFiles(); | ||
|
|
||
| //new bitmap image object | ||
| $image = new \OCP\Image(); | ||
| $image->loadFromData((string) $bp); | ||
| //check if image object is valid | ||
| return $image->valid() ? $image : null; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a preview of maxX times maxY dimensions in JPG format | ||
| * | ||
| * * The default resolution is already 72dpi, no need to change it for a bitmap output | ||
| * * It's possible to have proper colour conversion using profileimage(). | ||
| * ICC profiles are here: http://www.color.org/srgbprofiles.xalter | ||
| * * It's possible to Gamma-correct an image via gammaImage() | ||
| * | ||
| * @param string $tmpPath the location of the file to convert | ||
| * @param int $maxX | ||
| * @param int $maxY | ||
| * | ||
| * @return \Imagick | ||
| */ | ||
| private function getResizedPreview($tmpPath, $maxX, $maxY) { | ||
| $bp = new \Imagick(); | ||
|
|
||
| // Layer 0 contains either the bitmap or a flat representation of all vector layers | ||
| $bp->readImage($tmpPath . '[0]'); | ||
|
|
||
| // Fix orientation from EXIF | ||
| $bp->autoOrient(); | ||
|
|
||
| $bp->setImageFormat('jxl'); | ||
|
|
||
| $bp = $this->resize($bp, $maxX, $maxY); | ||
|
|
||
| return $bp; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a resized \Imagick object | ||
| * | ||
| * If you want to know more on the various methods available to resize an | ||
| * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im | ||
| * | ||
| * @param \Imagick $bp | ||
| * @param int $maxX | ||
| * @param int $maxY | ||
| * | ||
| * @return \Imagick | ||
| */ | ||
| private function resize($bp, $maxX, $maxY) { | ||
| [$previewWidth, $previewHeight] = array_values($bp->getImageGeometry()); | ||
|
|
||
| // We only need to resize a preview which doesn't fit in the maximum dimensions | ||
| if ($previewWidth > $maxX || $previewHeight > $maxY) { | ||
| // If we want a small image (thumbnail) let's be most space- and time-efficient | ||
| if ($maxX <= 500 && $maxY <= 500) { | ||
| $bp->thumbnailImage($maxY, $maxX, true); | ||
| $bp->stripImage(); | ||
| } else { | ||
| // A bigger image calls for some better resizing algorithm | ||
| // According to http://www.imagemagick.org/Usage/filter/#lanczos | ||
| // the catrom filter is almost identical to Lanczos2, but according | ||
| // to https://www.php.net/manual/en/imagick.resizeimage.php it is | ||
| // significantly faster | ||
| $bp->resizeImage($maxX, $maxY, \Imagick::FILTER_CATROM, 1, true); | ||
| } | ||
| } | ||
|
|
||
| return $bp; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / Psalm
UndefinedFunction