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

Generate only chosen sizes of previews #78

Closed
biva opened this issue Sep 14, 2017 · 7 comments
Closed

Generate only chosen sizes of previews #78

biva opened this issue Sep 14, 2017 · 7 comments
Milestone

Comments

@biva
Copy link

biva commented Sep 14, 2017

Thank you for this app!

I'd like to pre-generate only small previews of pictures, the ones used in a folder view for instance. And let the system generate larger preview when I ask for them. This would make the generation faster, and less space-consuming.

I tried to change these parameters in config.php:

  'preview_max_x' => 200,
  'preview_max_y' => 200,

It works well for the previewgenerator app. But it also prevents the system from generating larger preview when I click on it in the gallery for example. Would it be possible to chose which sizes can be pre-generated by the app?

This issue is related to #68 but the use case is not the same, so the solution could be different.

@biva
Copy link
Author

biva commented Sep 14, 2017

I looked into the commands, and I modified PreGenerate.php and also Generate.php, in private function calculateSizes():

  $maxW = 50;
  $maxH = 50;

But the max size generated keeps being 200 (the value I entered in config.php).

How should I modify these functions?

@biva
Copy link
Author

biva commented Sep 20, 2017

@rullzer Would you have any suggestion to help me out? Thank you in advance!

@rullzer
Copy link
Member

rullzer commented Sep 26, 2017

Aaah well $maxW and $maxH should do the trick.

The reason the bigger preview is generated is because that is how previews work in Nextcloud. From the original image we generate 1 'max preview'. Of the max sizes specified. That one is then used to generate all other previews from.

This is done so we don't try to load 9MB pictures in RAM each time ;)

@biva
Copy link
Author

biva commented Sep 27, 2017

Great, thank you!
Do you think it would be possible to add a parameter somewhere (in the Web UI, or in config.php), so that we can configure $maxW and $maxH easily?

@biva
Copy link
Author

biva commented Sep 27, 2017

I don't know how getSystemValue works exactly. I understand that it reads the 1st parameter, and if it doesn't exist, then it uses the second parameter. In this case, if 'preview_max_x' does not exist, then it uses 2048, correct?
$maxW = (int)$this->config->getSystemValue('preview_max_x', 2048);

Could it accept a third parameter? In this case, if the 2nd parameter doesn't exit, then it would use the 3rd parameter. Would it work?
$maxW = (int)$this->config->getSystemValue('preview_generator_max_x','preview_max_x', 2048);

@rullzer
Copy link
Member

rullzer commented Sep 27, 2017

Nah it doesn't work like that. I'll look into this at some point. But I can't promise a timeline.

@ArnisR
Copy link

ArnisR commented Nov 24, 2017

Don't use PreviewGenerator with default settings if you have many image files. By default NC12 have max preview width&height 2048 px. With these settings PreviewGenerator generates 20(!) previews for each image. It is insane. At first it takes time, but more importantly – it inflates oc_filecache table twentyfold.

The default logic how PreviewGenerator calculates sizes is factor by two from 32 px until reached max height/width. So it generates 3 sets (height, width, square) of previews with corresponding values: 2048, 1024, 512, 256, 128, 64, 32. It is 3x7-1(there is only one max size)=20 total.

At first I've checked which sizes generates NC12 itself in common scenarios. There are 32x32 small square thumbnails, medium previews in Gallery view with image height of 256 px, squared 256px for folder previews in Gallery and large preview defined by max settings in config.php. From mobile browser there were additional sizes, but I'm focused on computer use now.

I put max width 1500px, height 1000px in config.php and substitute preview size calculation with fixed values in PreGenerate.php and Generate.php.
Original:

	private function calculateSizes() {
		$this->sizes = [
			'square' => [],
			'height' => [],
			'width' => [],
		];

		$maxW = (int)$this->config->getSystemValue('preview_max_x', 2048);
		$maxH = (int)$this->config->getSystemValue('preview_max_y', 2048);

		$s = 32;
		while ($s <= $maxW || $s <= $maxH) {
			$this->sizes['square'][] = $s;
			$s *= 2;
		}

		$w = 32;
		while ($w <= $maxW) {
			$this->sizes['width'][] = $w;
			$w *= 2;
		}

		$h = 32;
		while ($h <= $maxH) {
			$this->sizes['height'][] = $h;
			$h *= 2;
		}
	}

Modified to:

	private function calculateSizes() {
		$this->sizes = [
			'square' => [32],
			'height' => [256, 1000],
			'width' => [1500],
		];

		$maxW = (int)$this->config->getSystemValue('preview_max_x', 2048);
		$maxH = (int)$this->config->getSystemValue('preview_max_y', 2048);

	}

So only 3 previews are generated: 32x32, ...x256, and max 1500/1000.
I don't pregenerate squared 256 px previews for folder because only first 4 pictures in folder used for this. If I have hundreds of pictures in folder, it would be waste of time and database.
I leave to NC to generate them itself. It doesn't take much time and needed only once.

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

No branches or pull requests

3 participants