Have you ever heard of Thumbor? This practical application has many features such as resizing, applying various features, and flipping images. The advantage of this tool is its ease of use because users only need to access the URL of the Thumbor service to make changes to images. In this article, we decided to introduce you to a Top Way to Setup Thumbor on Ubuntu 20.04.
As we mentioned in the introduction, Thumbor is a smart imaging service that cuts, resizes, and flips images based on your taste and desire. This tool uses advanced face recognition algorithms to determine the important points of images for better cropping and resizing. In fact, Thumbor is an Http service and is provided as a free and open-source service.
Now that you are somewhat familiar with the Thumbor service, let’s learn how to install and configure it, which is explained step-by-step in this section.
To install Thumbor you have to prepare some requirements:
– A Linux VPS with Ubuntu 20.04 OS
– Update the operating system
– A non-root user with sudo privileges and login with ssh
We have to mention that Thumbor is a Python service but you can use it for Ubuntu. So, use the apt command to install Thumbor on Ubuntu 20.04 and follow the instructions below to start the process:
– The first step is Updating the package information:
sudo apt update
– Use the following command to do the installation of Python virtual environment library:
sudo apt install python3-venv -y
– Then you should install the Thumbor dependencies:
sudo apt install build-essential libssl-dev libffi-dev python3-dev libcurl4-openssl-dev libcairo2-dev libjpeg-progs gifsicle ffmpeg -y
– To create a virtual environment use the below command:
python3 -m venv thumbor-venv
– Run the command below for activating the virtual command:
source thumbor-venv/bin/activate
– Now, you can use this command to install Thumbor:
(thumbor-venv) $ pip install thumbor[all]
If you want to check the status of dependencies, follow the command below:
(thumbor-venv) $ thumbor-Doctor
After the installation of Thumbor, you will see that all plugins and compiled libraries support this service.
In the Thumbor launch section, you should run the related command in the virtual environment:
(thumbor-venv) $ thumbor
Now, the application will run in your system’s foreground, on port 8888.
Using Thumbor is very easy through URL. So that, if you have an image and you want to resize or apply a filter, the location will be like this:
https://upload.wikimedia.org/wikipedia/commons/3/37/Acorus_calamus1.jpg
This is how you can pass an image to Thumbor through a URL.
If you want to open another ssh session on your server, you can access the image through the URL:
$ wget http://localhost:8888/unsafe/300x200/https://upload.wikimedia.org/wikipedia/commons/3/37/Acorus_calamus1.jpg -O small_pic.jpg
If you close the SSL session, the Thumbor command will die, and if you want to prevent that, run it in the background with screen or tmux.
The common way to run Thumbor is to run this service with supervisors or systems.
You can use another port for Thumbor. Run it on port 80 using sudo permission. The point is that this solution runs Thumbor outside of the Python virtual environment.
To deactivate the Thumbor command use Ctrl+C and deactivate Python virtual environment:
(thumbor-venv) $ deactivate
Now, run Thumbor with the full pass:
sudo thumbor-venv/bin/thumbor -p 80
Then use the command below to make sure that port 80 has been opened to the public:
sudo /sbin/iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
Use a browser to insert the URL and access Thumbor:
http://your_server_ip_address/unsafe/300x200/https://upload.wikimedia.org/wikipedia/commons/3/37/Acorus_calamus1.jpg.
Then, make sure you access the server with the HTTP protocol, and as the final step replace your_server_ip_address with your real IP address or domain.
For example, if you want to flip an image using a URL, you would do it like this:
http://your_server_ip_address/unsafe/-300x-200/https://upload.wikimedia.org/wikipedia/commons/3/37/Acorus_calamus1.jpg.
The -300 part will make the image flip horizontally and the -200 part means you flipped vertically.
If you want to configure and launch Thumbor, then you should kill it and start with the configuration file.
Use a configuration file to configure the behaviors of the Thumbor. The first step is creating a sample configuration file:
thumbor-venv/bin/thumbor-config > thumbor_sample.conf
The configuration file is full of comments:
################################### Logging #################################### ## Logging configuration as json ## Defaults to: None #THUMBOR_LOG_CONFIG = None ## Log Format to be used by thumbor when writing log messages. ## Defaults to: '%(asctime)s %(name)s:%(levelname)s %(message)s' #THUMBOR_LOG_FORMAT = '%(asctime)s %(name)s:%(levelname)s %(message)s' ## Date Format to be used by thumbor when writing log messages. ## Defaults to: '%Y-%m-%d %H:%M:%S' #THUMBOR_LOG_DATE_FORMAT = '%Y-%m-%d %H:%M:%S' ################################################################################ ################################### Imaging #################################### ## Max width in pixels for images read or generated by thumbor ## Defaults to: 0 #MAX_WIDTH = 0 ... ## Result Storage that will be used with the compatibility layer, instead of the ## compatibility result storage. Please only use this if you can't use up-to- ## date result storages. ## Defaults to: None #COMPATIBILITY_LEGACY_RESULT_STORAGE = None
Using the command below, you can edit the setting. Here, uncomment MAX_WIDTH set it like this:
MAX_WIDTH = 100
This action will show that you set the maximum width of the image that is allowed to be read.
Use the configuration file to run the Thumbor command:
sudo thumbor-venv/bin/thumbor -p 80 -c thumbor_sample.conf
In the following URL, you will see that the width of your image is much smaller than the height:
Open this URL, http://your_server_ip_address/unsafe/400x400/https://upload.wikimedia.org/wikipedia/commons/3/37/Acorus_calamus1.jpg.
To edit the configuration file, kill the Thumbor again. Now, you should uncomment FILE_STORAGE_ROOT_PATH and set it like this:
FILE_STORAGE_ROOT_PATH = '/tmp/storage'
Then use the configuration file and run Thumbor again and open the related URL:
http://your_server_ip_address/unsafe/400x400/https://upload.wikimedia.org/wikipedia/commons/3/37/Acorus_calamus1.jpg.
Here, do the same action again and kill the Thumbor. Thumbor will save your image in the /tmp/storage directory:
ls /tmp/storage
Now that you installed and configured Thumbor successfully, you can edit your images so easily. Enjoy the service.
By reading this content, you learned how to install and Setup Thumbor on Ubuntu 20.04. Thumbor is created for Python environments but you can use it on old Ubuntu versions. We hope you enjoyed this article. For any questions, just leave a comment below.
The default port is 8888, but if the virtual machine IP address is 12.123.12.123. Then you will be able to access Thumbor from the web browser at http://12.123.12.123:8888/…/
Image size of 1280*720 is large enough to be HD standards and is commonly used in photography and films.
How useful was this post?
Click on a star to rate it!
Average rating 5 / 5. Vote count: 1
No votes so far! Be the first to rate this post.
Chrony is a versatile and lightweight network time synchronization software available for various Li...
WSL (Windows Subsystem for Linux) on Ubuntu is a feature that allows users to run an Ubuntu terminal...
What is your opinion about this Blog?