Image manipulation server for resizing and converting images based on PHP.
The main goal is to run the HTTP server for image manipulation API.
This project is based on ReactPHP HttpServer.
As PHP extension, it supports libraries such as GD, Imagick or Imageflow.
Convert the image to another format: png, jpg, jpeg, webp
http://localhost:8080/pathname/image.jpg?format=webp
http://localhost:8080/pathname/image.jpg?format=png
Resize the image: width, height
http://localhost:8080/pathname/image.jpg?format=webp&with=100
http://localhost:8080/pathname/image.jpg?format=webp&with=100&height=100
Set quality: 0
- 100
http://localhost:8080/pathname/image.jpg?format=webp&quality=80
Set blurred: true
, false
http://localhost:8080/pathname/image.jpg?format=webp&blurred=true
First of all, clone the repository from GitHub:
git clone https://github.com/ucoderdev/php-image-server
Switch to the cloned folder in your terminal:
cd php-image-server
Install dependencies:
composer update
Create the configuration file:
php bin/setup.php
Before running the server, change the config.php
file.
The server will find all images from the images_dir
directory. Before starting the server, set it in the config.php
file.
The project supports PHP extensions
such as GD, Imagick or Imageflow. You can use any of them by changing the image_extension
value.
return array(
'images_dir' => '/path/domain.com/uploads',
'image_extension' => 'gd', // gd, imagick, imageflow
'port' => 8080,
'ip_address' => '127.0.0.1',
);
After configuration the server, you can start using CLI:
php bin/run.php
Note: By default the server starts on port 8080
.
Note: By default the server starts at 127.0.0.1
.
If you want to run the server in a background, you can use PM2 or nohup.
Running in PM2:
pm2 start bin/run.php --name=php-image-server
Running in nohup:
nohup php bin/run.php &
Below is the NGINX configration:
server {
...
autoindex off;
location / {
autoindex off;
proxy_pass http://127.0.0.1:8080;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
...
}
Install Rust by running
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
Ensure build tools are installed (git, curl, wget, gcc, g++, nasm, pkg-config, openssl, ca-certificates)
sudo apt-get install git wget curl build-essential pkg-config libssl-dev libpng-dev nasm
Clone and cd into this repository
git clone https://github.com/imazen/imageflow.git && cd imageflow
If you are using bash on any platform, you should be able to use build.sh
./build.sh clean
: clean./build.sh release
: generate release binaries./build.sh install
: install release binaries to /usr/local
Detailed installation:
https://github.com/imazen/imageflow/blob/main/README.md#building-from-source-without-docker
The repository is open-sourced software licensed under the MIT license.
If you discover a security vulnerability, please contact me at hello@ucoder.dev.