Open Source PHP API for Processing Image
Create & manipulate responsive images via PHP commands. Rotate, crop, resizes image keeping the aspect ratio and image conversion to other formats via PHP.
Imagecow is a very powerful and stable open source library for handling image processing capabilities inside PHP applications. The library is very useful for creating and manipulating responsive images. The library is very simple, fast, and easy to use. The library uses GD2 or Imagick libraries and can be extended with more if required.
This Imagecow open source PHP library gives developers the ability to manipulate images to the web. The API has provided support for several advanced image processing features such as rotate images, generate responsive images, resizes image keeping the aspect ratio, image conversion to other formats, cropping images, image cloning, apply watermark on the image, apply image compression quality, Draw text along a path and many more.
At A Glance
An overview of Imagecow features.
- Image conversion
- Resize images
- Edit images
- Image cloning
- Apply watermark
- Display images
- Image compression
- Draw text
- Cropping images
- Image effect
- Image encoding
Imagecow works with PHP 5.3 & above.
Getting Started with Imagecow
The recommended way to install Imagecow is via Composer. Please use the following command to install ut.
Install Imagecow via Composer
$ composer require imagecow/imagecow
Create Responsive Images via PHP APIs
Create Responsive Images via PHP APIs
$file = __DIR__.'/'.$_GET['file']; $transform = isset($_GET['transform']) ? $_GET['transform'] : null; //Create the image instance $image = Image::fromFile($file); //Set the client hints $image->setClientHints([ 'dpr' => isset($_SERVER['HTTP_DPR']) ? $_SERVER['HTTP_DPR'] : null, 'width' => isset($_SERVER['HTTP_WIDTH']) ? $_SERVER['HTTP_WIDTH'] : null, 'viewport-width' => isset($_SERVER['HTTP_VIEWPORT_WIDTH']) ? $_SERVER['HTTP_VIEWPORT_WIDTH'] : null, ]); //Transform the image and display the result: $image->transform($transform)->show();
Resize Images using PHP API
Knowing how to resize images is very useful and helps to reduce the file size as much as possible and keep the image quality. The Imagecow library allows PHP programmers to resize images inside their own applications. You can resize the image keeping the aspect ratio, You need to provide the new max-width of the image as well as the new max-height of the image. The Imagecow supports calculating the most important parts of the image to crop and resizeCrop automatically.
Resize Image via PHP Library
//Assuming the original image is 1000x500 $image->resize(200); // change to 200x100 $image->resize(0, 200); // change to 400x200 $image->resize(200, 300); // change to 200x100 $image->resize(2000, 2000); // keeps 1000x500
Flip, Crop or Rotate Images via PHP
The Imagecow gives software developers the capability to flip, crop, or rotate their images using PHP commands inside their applications. The library supports auto-resizing and cropping the image with ease. Developers can rotate an image to a specific angle with just a couple of lines of code. Moreover, you can set the opacity of the image as well as apply the Gaussian blur to the image.
How to Rotate Image via PHP?
require __DIR__.'/bootstrap.php'; use Imagecow\Image; $image = Image::fromFile(__DIR__.'/my-image.jpg', $library); $image->rotate(90); $image->show();
Applying Watermark on Image
The open source library Imagecow has provided functionality for applying watermark on the image inside their own applications. You can add a watermark to your digital photos to protect them and prohibit people from using the images without your permission. Developers can programmatically add a watermark to an image and can configure the position and opacity with ease.
Add Watermark to Images via PHP?
$image = Image::fromFile('photo.jpg'); $logo = Image::fromFile('logo.png'); $logo->opacity(50); $image->watermark($logo);