Skip to content
Offerel edited this page Jul 1, 2024 · 6 revisions

Pictures Plugin

This is a very simple pictures/gallery plugin for Roundcube. You can view your personal photos that are synced to your personal storage in a easy way. This plugin does not sync itself, it gives you only easy access to the synced photos. To sync your photos, you can use any sync software/system which can automatically sync the photos from your smartphone (or any other device) to a storage accessible by Roundcube.

Installation

  • Extract the downloaded archive into Roundcube’s plugin directory <roundcube>/plugins/ and rename it to pictures.
  • Copy config.inc.php.dist to config.inc.php
  • Change $config['pictures_path'] and $config['thumb_path']. This defines, where the photos for your gallery are stored. The second path, is where the tumbnails are stored. You can use the '%u' variable to complete the path with the current username. All paths should be read and writeable by the webserver user (www-data)
  • You can specify folders and images you didn't want to see in your gallery in the option $config['skip_objects']
  • Activate the plugin in /config/config.inc.php in the way that you add it to the active plugins array, like $config['plugins'] = array('pictures');

Update the images

Of course you can also update your images. A user can upload images at any time via the web interface. The images are then analyzed and thumbnails are generated. The same applies to deleting images. The thumbnails and database entries are deleted or updated directly. There is also a automatic generation of webp versions of the photos and converting videos to a weblike format.

Of course, this automatic function does not work if images are uploaded from other devices, for example from a smartphone or digital camera. Roundcube is usually unaware of such a process. I have therefore created a maintenance script for such situations. All you have to do is ensure that this script is started.

In the simplest case, the script is started automatically at regular intervals with a scheduler such as crontab. The script must be started with the same user under which the web server is running in order to avoid problems with privileges. An example call would be: /usr/bin/php -f /path/to/your/maintain.php

The call via a scheduler has various disadvantages. For example, the images are only updated at set times. This means that a considerable amount of time can pass between upload and availability in the gallery. With systemd services you have a more efficient option. Among other things, there are so-called path units. These can be triggered when something changes in a file path. I personally use an Android app called "FolderSync" to upload images from my smartphone to the server. After the upload, the app can call up a webhook and transmit the result of the sync. The Roundcube Pictures plugin can use this request. The URL required for this looks something like this:

https://your.server.com/roundcube/?_task=pictures&fsync=1

You request the Roundcube Pictures plugin and pass the parameter fsync with the value 1 for a successful sync or 2 for an error. The plugin writes this result to a log file in the Roundcube log directory.

This log file can be monitored by the systemd path unit referred to. A simple path unit for this purpose could look like this:

[Unit]
Description=Monitor Roundcube Pictures Logfile for changes

[Path]
PathModified=/var/log/roundcube/fssync.log
Unit=foldersync.service

[Install]
WantedBy=multi-user.target

Only the path to the Roundcube log directory needs to be adjusted here. Save this file as /etc/systemd/system/foldersync.path. Furthermore, a 2nd unit with the name foldersync.service is mentioned. If path unit is activated and the content of the log file changes, foldersync.service is called immediately. The content of this file should look similar to the following:

[Unit]
Description=Executes Roundcube Pictures Maintenenance Script

[Service]
Type=simple
User=www-data
Group=www-data
ExecStart=/usr/bin/php /path/to/roundcube/plugins/pictures/maintain.php
Restart=on-failure

[Install]
WantedBy=multi-user.target

If your web server user is different from www-data, please adjust this accordingly. The path to the maintenance script must of course also be adjusted. This unit starts the maintenance script with the named user. This is only started if something has changed, the start takes place directly after the upload was successful.

This can take some time with large quantities in such an upload. So that the admin can be informed about the completion of the maintenance, it is possible to send a notification via ntfy on completion. This must be activated in config.inc.php. The notification is only sent if the runtime is longer than 15 minutes.

Issues

How to report bugs

If the plugin does not work as expected, the errors can be reported as new issues. I will try to fix the problem. However, I need your help to find the cause of the problem. Important are especially some log files.

  • This is mainly the output of the browser's webconsole. In most browsers under Windows, you can access it by pressing the F12 key, please tell me all listed errors and warnings.
  • The output of the Roundcube error log file is also useful.
  • Sometimes the cause is also the server configuration. There are two logfiles of the webserver: error.log and access.log
  • PHP errors should be logged in a separate PHP error logfile

Please also note that I can only give very limited tips and advice on server configuration. Server configuration is mostly up to you or your hosting provider.

FAQ

Which formats are supported?

Supported formats are jpg, jpeg, webp, mp3, mp4, 3gp, and png files. Other formats are not tested yet. MP4 and 3gp support is only available, when ffmepg or avconv are installed.

The first start is really slow

If you start the plugin the first time, there are no thumbnails available. They are generated in the first call. The next call should be fester. However you can try to experiment with $config['thumbs_pr_page'] to display a few less images on the page if it takes a to long time. Or when your server is fast enough, you can raise the picture count. But please be aware, that every picture is at least one HTTP request and some SQL query's. See this as a small warning, to not display to many pictures to to prevent timeouts.

Can i do anything against generating thumbnail's only by visit the picture first?

Yes, you can. I have written a file maintain.php. I recommend to run this script before your first visit to the gallery. It is designed as a PHP-CLI-Script. To the nature of this scripts, they don't have any timeout issues and can run a very long time. This script generates thumbnails for ALL users in Roundcube. There are 3 options for this script: "add", "clean" and "all". With "add" you can only add new thumbnails. "clean" will remove orphaned thumbnails and "all" is a combination of both options. Additionally to the initial run, you can set this script as a cronjob, to let it maintain your gallery in a more regular schedule. Since i sync all my smartphone pictures at night, when the phone load the battery, i let it run once a day. It's up to you, but please be aware, that you should run it as the webserver user (www-data in most cases) and under no circumstances as root!

Can i share my photos?

Yes. You can. This is a new feature added some weeks ago. Sharing Photos will create some sort of special Album with a special link. You can share this link with everyone you want. Everyone with this link can view, but not edit, delete or add photos.

Some folders/album have no thumbnail. Why?

Only when a folder has images in it, they are used as a thumbnail. If a folder has no images, no thumbnails can be created. A folder with only some sub-folders as content, does not have images and as such no thumbnails can be generated. For a folder thumbnail, the latest image by date (EXIF, not the file-date) is used for the thumbnail. However, if you place a image with the name "folder.jpg" in a folder, this "folder.jpg" is used to represent the thumbnail for that folder. The "folder.jpg" is not take in account as photo and as such not displayed as photo in a album.

Albums and folders

An album is stored in the file system as a folder. Thus, folder and album are synonymous with each other. This means that an album can also have a sub-album. Albums can be created thus also over the file system.

If the plugin does not work as expected, the errors can be reported here as new issues. I will then try to fix the problem. However, I need your help to find the cause of the problem. Important are especially the different log files.

Folder "Incoming

This folder is meant for new photos to "arrive" unsorted. For example pictures from the digital camera or from the smartphone. From here, the images can be moved to existing albums or deleted. This folder should therefore never be deleted.

Thumbnails

Normally albums get their thumbnails automatically from the respective content of the folders. The first image of the folder is used for this purpose. Usually this is the oldest one. But if a folder has only subfolders, there are no direct images in the folder from which a preview can be created. In this case, a default gray image is used. Alternatively, you can place any image named "folder.jpg" in the folder. This image will not be displayed as an image in the folder but will be used as a preview image. A custom "folder.jpg" also overwrites the preview automatically created from the content.

Sometimes newly uploaded images via manual uploads are not visible as previews. The preview is generated automatically overnight or manually via the maintenance script if required. Images uploaded via the web interface receive a preview immediately.