Imagemagick (or similar) convert command on file upload (Flow)

Hi,

I have a use case which I haven’t found anyone else posted about online yet, where I’d like to run imagemagick convert-command based on a automated tag when a file is uploaded.

Example:

  1. User uploads image.jpg
  2. Flow Automated Tagging ensures that image.jpg is tagged image
  3. Flow with External Scripts-app runs command convert image.jpg -resize 1000x1000/> on all files that is tagged image

As I’ve found elsewhere in the forum it seems like php-imagemagick have been disabled out of security reasons, which is perfectly fine. In my case the server will be local and only utilized by trusted users, so the security concern is not relevant in my case - but if we can keep the instance secured that’s definately preferred.

Is there any alternative software that can be used to run a similar command? Is there any workaround to call a bash script outside of NC to execute it only server-side? Any examples of how to implement this?

Any help and/or guidance would be greatly appreciated :slight_smile:

BTW, trying to execute commands without using the full path to it, will most likely not work because the command couldn’t be found by the app :wink:

  • Afaik, the imagemagick convert command isn’t part of the php package but a normal command line tool, so why shouldn’t it be possible to use it?

  • Why should a workaround be needed to run a simple shell script? I solved a similar problem by using the workflow_script app. The following posting might lead you into the right direction:

Thanks for your feedback. I’ve been trying to wrap my head around this now for a while, but can’t seem to get it sorted. The problem is that I find the logging really hard to interpret even though I’ve enabled debugging.

The command I’m trying to run is the following and I’ve verified that the www-data user is able to run this in any folder applicable. It works excellent server-side:
sudo -u www-data /usr/bin/convert <path/to/file> -interlace plane -strip -quality 80 -resize 1000x1000\> -set filename:new '%t_1' ../%[filename:new].jpg

When I then try to run this via the workflow script, the logging give me feedback that it was successful to run the command which in the GUI looks like this:
/usr/bin/convert /mnt/product-images-sync/%n -interlace plane -strip -quality 80 -resize 1000x1000\> -set filename:new '%t_1' ../%[filename:new].jpg

Unfortunately nothing happens at this point, even though the log output for %n and the static set path definately matches the full working path for the file itself. I then tried to convert this line to a bash script to get workflow log output as suggested by you from other threads in relating matters, but have been unsuccessful at that part too.

This is how it looks inside Flow (GUI)

And this is my bash script:

   #!/bin/sh
    exec 2>/tmp/workflow_script-trace-$$.txt
    set -x

    if [ -n = $1 ]
    then
            /mnt/usr/bin/convert /mnt/product-images-sync/$1 -interlace plane -strip -quality 80 -resize 1000x1000\> -set filename:new '%t_1' ../%[filename:new].jpg
    fi

I’m really out of my depth here as I’m not very familiar with scripting myself.

Any ideas of how I could get this working properly? :slight_smile:

Ok, so I managed to get workflow script log output and it seems like the path provided isn’t correct, but naturally also adds the /<user>/<folder>/ in the beginning, which isn’t applicable to me since I’m using a locally mounted folder (via external storage).

Now I’m trying to manage to remove that part from the variable…

You could also just install php-imagick on the server. I did in Debian with:

$ apt-get update && apt-get -y install php-imagick --no-install-recommends

Ok, so I managed to get workflow script log output and it seems like the path provided isn’t correct, but naturally also adds the /// in the beginning, which isn’t applicable to me since I’m using a locally mounted folder (via external storage).

I think your assumption is wrong, because Nextcloud always uses this structure to access user specific files. As written in the app documentation you need to prefix the path with the Nextcloud data path to access any files in the Nextcloud environment, like “<nextcloud-data-path>/<user>/files/<the-relevant-directory-from-the-Nextcloud-user-root>