Skip to content
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

temporary high quality images #652

Open
JanisPlayer opened this issue May 17, 2023 · 3 comments
Open

temporary high quality images #652

JanisPlayer opened this issue May 17, 2023 · 3 comments
Labels
feature New feature or request

Comments

@JanisPlayer
Copy link

JanisPlayer commented May 17, 2023

https://github.com/pulsejet/memories/tree/master/src/native.ts#L16
https://github.com/pulsejet/memories/tree/master/src/components/viewer/Viewer.vue#L808
I have a feature idea for the app:
IMAGE_HQ_PREVIEW
This is an image that is generated with 100% quality and max resolution. It may put some load on the CPU but can save bandwidth and achieve the same results as loading the full image. JPEG could be used, which can be processed quickly, or bandwidth-saving WebP, which also offers fast processing. The generation could be integrated here or a separate file could be created like /lib/Controller/Previewer.php. Then, in /src/components/viewer/Viewer.vue, you can simply request the IMAGE_HQ_PREVIEW when, for example, zooming is performed. One could go further and create a cache with a maximum size and file count.
What would you think of the idea?

I have a question, how do you change the FFmpeg quality setting from "Faster" to "Ultrafast"?
https://github.com/pulsejet/memories/blob/master/docs/system-config.md
https://github.com/pulsejet/memories/blob/master/docs/hw-transcoding.md

Oh, and I think the app is fantastic. I had a similar idea recently, and then someone recommended your app to me. It's already working very well, there was only one installation error, which could be easily fixed.

@JanisPlayer JanisPlayer added the feature New feature or request label May 17, 2023
@pulsejet
Copy link
Owner

This is an image that is generated with 100% quality and max resolution. It may put some load on the CPU but can save bandwidth and achieve the same results as loading the full image. JPEG could be used, which can be processed quickly, or bandwidth-saving WebP, which also offers fast processing. The generation could be integrated here or a separate file could be created like /lib/Controller/Previewer.php. Then, in /src/components/viewer/Viewer.vue, you can simply request the IMAGE_HQ_PREVIEW when, for example, zooming is performed. One could go further and create a cache with a maximum size and file count.
What would you think of the idea?

I'm a bit confused. This is more or less exactly what is done right now (see). When the user zooms into the image, the image is converted to JPEG server-side and displayed to the user.

I have a question, how do you change the FFmpeg quality setting from "Faster" to "Ultrafast"?

For now, you'll need to compile go-vod yourself. Make sure you use the correct version tag.

@JanisPlayer
Copy link
Author

JanisPlayer commented May 17, 2023

private function getImageJPEG($blob, $mimetype): array

Yes I totally missed it and didn't look into the function, I thought it just called the original image.
So then I could just change that to WebP, cool.
Then my functional idea would actually be to add more formats such as quality, maxWidth, maxHeight settings.
And an option is to be added so that it always converts to the format you want.

            $format = $this->config->getSystemValueString('memories.preview.format', 'jpeg');
            switch ($format) {
              case 'jpeg':
                $format = 'jpeg';
                break;
              case 'webp':
                $format = 'webp';
                break;
              case 'avif':
                $format = 'avif';
                break;
              default:
                $format = 'jpeg';
            }
            $image->setImageFormat($format);

            $quality = (int)$this->config->getSystemValue('memories.preview.quality', '95');
            if ($quality < 0 || $quality > 100) {
                //throw Exceptions::Forbidden('Warning: You have set an invalid quality value for image conversion');
            }
            $image->setImageCompressionQuality($quality);

            // Set maximum width and height
            $maxWidth = (int)$this->config->getSystemValue('memories.preview.x', '0');
            $maxHeight = (int)$this->config->getSystemValue('memories.preview.y', '0');

            // Get current dimensions
            $width = (int)$image->getImageWidth();
            $height = (int)$image->getImageHeight();

            // Calculate new dimensions while maintaining aspect ratio
            if($maxWidth != 0 && $maxHeight != 0) {
              if ($width > $maxWidth || $height > $maxHeight) {
                $aspectRatio = $width / $height;
                if ($width > $height) {
                    $newWidth = $maxWidth;
                    $newHeight = $maxWidth / $aspectRatio;
                } else {
                    $newHeight = $maxHeight;
                    $newWidth = $maxHeight * $aspectRatio;
                }
                  // Resize the image
                  //$image->resizeImage((int)$newWidth, (int)$newHeight, \Imagick::FILTER_CATROM, 1); Dont Work
                  $image->scaleImage((int)$newWidth, (int)$newHeight);
              }
            }

// Convert image to JPEG if required
$format = $this->config->getSystemValueString('memories.preview.format', 'false');
if (!\in_array($mimetype, ['image/png', 'image/webp', 'image/jpeg', 'image/gif'], true) || $format= false) {

Warning this is untested sample code, it's just meant to explain an idea better.
But I'll make a version that you could include.
Update: I test it and it works. :)
So finish, i try to make a pull for this:
JanisPlayer@e613076

For now, you'll need to compile go-vod yourself. Make sure you use the correct version tag.

Thanks will try.

@pulsejet
Copy link
Owner

pulsejet commented May 17, 2023

Moved to #653 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants