editor: heic

pull/221/head
Varun Patil 2022-11-09 22:43:58 -08:00
parent 0074647b21
commit 515f0c48eb
6 changed files with 34 additions and 12 deletions

View File

@ -13,6 +13,7 @@ This file is manually updated. Please file an issue if something is missing.
- Fix stretched images in viewer ([#176](https://github.com/pulsejet/memories/issues/176))
- Editor: Restore metadata after image edit ([#174](https://github.com/pulsejet/memories/issues/174))
- Editor: Fix loss of resolution after edit
- Editor: Allow editing all image formats (HEIC etc.)
## v4.6.1, v3.6.1 (2022-11-07)

View File

@ -54,6 +54,7 @@ return [
['name' => 'Image#info', 'url' => '/api/image/info/{id}', 'verb' => 'GET'],
['name' => 'Image#setExif', 'url' => '/api/image/set-exif/{id}', 'verb' => 'PATCH'],
['name' => 'Image#jpeg', 'url' => '/api/image/jpeg/{id}', 'verb' => 'GET'],
['name' => 'Archive#archive', 'url' => '/api/archive/{id}', 'verb' => 'PATCH'],

View File

@ -135,11 +135,11 @@ class ApiBase extends Controller
}
/**
* Get a file with ID from user's folder
* Get a file with ID from user's folder.
*
* @param int $fileId
*
* @return File|null
* @return null|File
*/
protected function getUserFile(int $id)
{
@ -156,7 +156,7 @@ class ApiBase extends Controller
}
// Check if node is a file
if (!($file[0] instanceof File)) {
if (!$file[0] instanceof File) {
return null;
}

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace OCA\Memories\Controller;
use OCA\Memories\AppInfo\Application;
use OCA\Memories\Exif;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
@ -96,25 +97,35 @@ class ImageController extends ApiBase
}
/**
* Get a full resolution PNG for editing from a file.
* @NoAdminRequired
*
* @NoCSRFRequired
*
* Get a full resolution JPEG for editing from a file.
*/
public function getPNG(string $id)
public function jpeg(string $id)
{
$file = $this->getUserFile((int) $id);
if (!$file) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
// Get the image info
$info = $this->timelineQuery->getInfoById($file->getId(), true);
// check if valid image
$mimetype = $file->getMimeType();
if (!\in_array($mimetype, Application::IMAGE_MIMES, true)) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
// Get the image
$path = $file->getStorage()->getLocalFile($file->getInternalPath());
$image = Exif::getPNG($path, $info['exif']);
$image = new \Imagick($path);
$image->setImageFormat('jpeg');
$image->setImageCompressionQuality(95);
$blob = $image->getImageBlob();
// Return the image
$response = new Http\DataDisplayResponse($image, Http::STATUS_OK, ['Content-Type' => 'image/png']);
$response->cacheFor(0);
$response = new Http\DataDisplayResponse($blob, Http::STATUS_OK, ['Content-Type' => $image->getImageMimeType()]);
$response->cacheFor(3600 * 24, false, false);
return $response;
}

View File

@ -32,8 +32,17 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
private imageEditor: FilerobotImageEditor = null;
get config(): FilerobotImageEditorConfig & { theme: any } {
let src: string;
if (["image/png", "image/jpeg", "image/webp"].includes(this.mime)) {
src = this.src;
} else {
src = generateUrl("/apps/memories/api/image/jpeg/{fileid}", {
fileid: this.fileid,
});
}
return {
source: this.src,
source: src,
defaultSavedImageName: this.defaultSavedImageName,
defaultSavedImageType: this.defaultSavedImageType,

View File

@ -586,7 +586,7 @@ export default class Viewer extends Mixins(GlobalMixin) {
}
get canEdit() {
return ["image/jpeg", "image/png"].includes(this.currentPhoto?.mimetype);
return this.currentPhoto?.mimetype?.startsWith("image/");
}
private openEditor() {