I am watermarking JPGs with PNGs and then displaying them to users. I’m using a combination of PIL and OpenCV to create the watermark and then applying the watermark to the JPG. I was surprised to find that it took 1.5s from start to finish. I assumed that the bottleneck would be the graphics operations, but after timing every single line, I found that saving the watermarked JPG to SSD was the biggest culprit - 0.7s to 1s to save about 700kb images. I tried saving the image to memory in a BytesIO object, but that takes longer (1-1.5s).
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hi there,
Indeed, you can upgrade to a Storage-Optimized Droplet which use NVMe (non-volatile memory express), which is an interface protocol explicitly built for modern SSDs:
You can try creating a storage-optimized Droplet and deploying your application there as a test, rather than upgrading your existing Droplet directly. That way you will be able to verify if this improves the speed.
Also, another thing to keep in mind is that when you save an image using OpenCV or PIL, they have to encode the pixel data in the JPEG format. This is a CPU-bound operation, which means a faster CPU will perform it quicker. However, there are also libraries specifically designed for fast JPEG encoding/decoding, such as libjpeg-turbo, that you could potentially use:
Another thing you could try is to compress your images, as a smaller file size means less data to write to the disk. If image quality isn’t a top priority, you can consider lowering the quality level or changing the image resolution before saving.
Hope that this helps!
Best,
Bobby