previewgenerator icon indicating copy to clipboard operation
previewgenerator copied to clipboard

previewgenerator with Nextcloud Preview

Open fuzunspm opened this issue 5 years ago • 6 comments

Should i use/add enable_preview parameter in config.php and put desired file extensions to use this ? Asking because some file types seems to be not working like .mov, .mp4 and .heic

fuzunspm avatar Nov 29 '20 08:11 fuzunspm

I added the following in config.php and afterwards everything worked except PDFs, PDFs needed adjustment in ImageMagick policy in /etc/ImageMagick-6/policy.xml

Add this in config.php

  'enable_previews' => true,
  'enabledPreviewProviders' =>
   array (
    0 => 'OC\\Preview\\TXT',
    1 => 'OC\\Preview\\MarkDown',
    2 => 'OC\\Preview\\OpenDocument',
    3 => 'OC\\Preview\\PDF',
    4 => 'OC\\Preview\\MSOffice2003',
    5 => 'OC\\Preview\\MSOfficeDoc',
    6 => 'OC\\Preview\\PDF',
    7 => 'OC\\Preview\\Image',
    8 => 'OC\\Preview\\Photoshop',
    9 => 'OC\\Preview\\TIFF',
   10 => 'OC\\Preview\\SVG',
   11 => 'OC\\Preview\\Font',
   12 => 'OC\\Preview\\MP3',
   13 => 'OC\\Preview\\Movie',
   14 => 'OC\\Preview\\MKV',
   15 => 'OC\\Preview\\MP4',
   16 => 'OC\\Preview\\AVI',
  ),

And change this line in /etc/ImageMagick-6/policy.xml from <policy domain="coder" rights="none" pattern="PDF" /> to <policy domain="coder" rights="read|write" pattern="PDF" /> and then do a PHP restart systemctl restart php7.4-fpm

Why this is not in the Readme or mentioned anywhere else is beyond me...

XXDoMi77 avatar Dec 07 '20 07:12 XXDoMi77

Should I re run generate all command again after these changes?

Thank you very much btw

fuzunspm avatar Dec 07 '20 07:12 fuzunspm

If you have run it already then probably not, but you can, it skips over the ones which are already done...

XXDoMi77 avatar Dec 07 '20 07:12 XXDoMi77

I added the following in config.php and afterwards everything worked except PDFs, PDFs needed adjustment in ImageMagick policy in /etc/ImageMagick-6/policy.xml

Add this in config.php

  'enable_previews' => true,
  'enabledPreviewProviders' =>
   array (
    0 => 'OC\\Preview\\TXT',
    1 => 'OC\\Preview\\MarkDown',
    2 => 'OC\\Preview\\OpenDocument',
    3 => 'OC\\Preview\\PDF',
    4 => 'OC\\Preview\\MSOffice2003',
    5 => 'OC\\Preview\\MSOfficeDoc',
    6 => 'OC\\Preview\\PDF',
    7 => 'OC\\Preview\\Image',
    8 => 'OC\\Preview\\Photoshop',
    9 => 'OC\\Preview\\TIFF',
   10 => 'OC\\Preview\\SVG',
   11 => 'OC\\Preview\\Font',
   12 => 'OC\\Preview\\MP3',
   13 => 'OC\\Preview\\Movie',
   14 => 'OC\\Preview\\MKV',
   15 => 'OC\\Preview\\MP4',
   16 => 'OC\\Preview\\AVI',
  ),

And change this line in /etc/ImageMagick-6/policy.xml from <policy domain="coder" rights="none" pattern="PDF" /> to <policy domain="coder" rights="read|write" pattern="PDF" /> and then do a PHP restart systemctl restart php7.4-fpm

Why this is not in the Readme or mentioned anywhere else is beyond me...

Thanks a lot for posting this @XXDoMi77 ! 🥇 I was searching for days why PDF previews stopped working. I did not have to change this in previous NC versions.

jo-me avatar Dec 13 '20 14:12 jo-me

I'm hitting performance and space issues related to previews (my server freezes when I upload more than about 10 photos and when preview generation is enabled). I tried to see if Preview Generator app could help, then realized I was confused about the interaction between Preview Generator app and Nextcloud Preview. So I ran a few tests and attempted to answer my questions below. This is very partial, and help is welcome.

  1. Can Preview Generator help save CPU by postponing preview generation to some time after upload?
  • Preview Generator app does not overrides Nextcloud Preview. Even with Preview Generator app is installed, Nextcloud Preview will continue to generate previews on demand regardless of Preview Generator app configuration.
  • Setting enable_previews to false in config.php not only disables preview generation by Nextcloud Preview, but also disables preview display, even of existing preview (this was not clear in current doc) . It means that currently, there seem to be no way to decorrelate generation and display of previews.
  • Setting enable_previews to false in config.php also disables preview generation by Preview Generaror app (i.e. preview:generate-all won’t generate any preview when enable_previews is false).
  1. Save space and CPU by limiting the number of generated previews [The section below attempts to list which apps request which preview at the time of writing this comment. It would be great to have this list documented and maintained so as to be able to tune Preview Generator accordingly]
  • On upload, Nextcloud Preview generates (here for a landscape photo):    - (a) one preview at preview_max_x width    - (b) one preview at 1024 width if "Crop image previews" toggle is off, or one preview at 1024 crop if "Crop image previews" toggle is on.
  • On click on photo file (to view it), Nextcloud generates no preview.
  • On click on photo size or modified date (which opens the right side activity panel), Nextcloud Preview generates:    - (c) one preview at 1024 height (and larger width)
  • On opening the Gallery, Nextcloud Preview generates:    - (d) one 256 crop preview
  • Opening the Nextcloud Photos mobile app generates no additional preview.

Based on these tests, it seems that 1024 and 256 are hardcoded somewhere. It would be great to add this to the documentation, and maybe to propose a default configuration for Preview Generator app that follows these values.

For my need, a way to reduce the number of generated preview is to set preview_max_x and preview_max_y to 1024, and to turn the "Crop image previews" toggle off. This way, only two previews are generated ((a) and (d) above).

  1. Save space by deleting old previews In my case occ files:scan-app-data doesn't work at the moment. I believe this is related to my storage type being primary object storage. Is there a solution (even manual) to safely delete old previews ?

charleypaulus avatar Sep 28 '22 05:09 charleypaulus

Save space by deleting old previews In my case occ files:scan-app-data doesn't work at the moment. I believe this is related to my storage type being primary object storage. Is there a solution (even manual) to safely delete old previews ?

Correct. This method does not work on object storage. There is no manual method (yet). However, there is an automated background job which cleans old previews every now and then.


One thing on limiting CPU usage: It is possible to limit parallel preview generation jobs at runtime via the preview_concurrency_all and preview_concurrency_new configs. Settings those will prevent overloading your server when users browse directories with large amounts of pictures.

Ref https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#previews

st3iny avatar Feb 10 '23 14:02 st3iny