I've recently taken over an ecommerce website (example.com) and I'm looking to make some improvements to how media files are delivered. Currently when an image is uploaded for a product, the process is as follows:

  • Image is stored locally
  • Metadata is stripped
  • Multiple sizes of the image are created for various thumbnails around the website
  • Watermark is applied
  • Images (including the original) are copied to Digitalocean Spaces and served through CDN
  • Local copies are removed

The website also has videos for some products. We currently use Ffmpeg to create thumbnails and use the same flow as above to store.

There are thousands of products so this feels incredibly long-winded and it's not maintainable if we want to add an additional thumbnail size or change the watermark for example.

We use Cloudflare and I know they offer an image optimization service. However, I can't see any way that integrates with Spaces or S3. This will only work with images on the example.com domain. E.g. example.com/w:200,h:200/images/image-01.jpg.

I'm therefore toying with the idea of creating a new subdomain, server and CF zone entirely for images and videos. E.g. media.example.com, moving away from cloud object storage and just storing everything on a linux server with a CDN in front of it. This feels like a bit of a backward step and will be a pretty big task so just wondered whether this is the best solution or if anyone has a better one?

Thank you


1 Answer 1


Do you have a Linux sandbox setup?

Linux by default uses bash as the default shell. Bash is more than a command prompt it is a full language with variables, conditional statements, loops, functions, etc. As Linux is more or less a developer platform almost every program works like an API within the bash shell or "script."

You can get the workflow established on the sandbox and then turn that workflow into a bash script, which can run as a cron job.

As a example not a recommendation of Linux command applications to match your workflow.

echo "remove meta data"
exiftool -all= image.jpg

echo "resize image" 
convert image.jpg -resize 100x100 image_100x.jpg

echo "add water mark"
COMPOSITE -gravity SouthEast watermark.png image_100x.jpg image_done_100x.jpg

echo "upload image"
scp image_done_100x [email protected]:/this/path/right/here

echo "remove image"
rm image*.jpg

exiftool, convert, and Composite I believe are all part of the Imagemagick API / (application) but I'm not suggesting which programs to use.

scp would be the command line method to upload a file.

rm is the command in Linux to Delete a file or files.

Once you have the commands worked out, copy them to yourname.sh and use bash yourname.sh to run.

And yes you can move that to the Linux server, but then change

echo "upload image"
scp ...


echo "move image"
mv /sourcepath/image.jpg /this/path/right/here/image.jpg

of course, you will likely want to use a directory IE ~/source_images/ and use a variable with a loop to go through all the images process them and make them live.

The process of replacing your work with a program in Linux is to literally put the commands into a file and call it a bash script. Then run the script and watch it while you drink coffee. The terminal is literally just another file that the system needs to wait on because its data rate is very slow, and it is ran like any other file, just slowly because it has lots of typos in the code.


You can execute a shell command from PHP but doing it that way means using CPU time for each request. And I have personal discomfort over safety from a security point of view of doing so. If the image sizes are known in advanced the system can do the CPU work once and create the static image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.