PHP code example of marcha / imagecow

1. Go to this page and download the library: Download marcha/imagecow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marcha / imagecow example snippets


use Imagecow\Image;

//Create an Imagick instance of "my-image.jpg" file:
$image = Image::create('my-image.jpg', 'Imagick');

//Create an instance detecting the library automatically
$image = Image::create('my-image.jpg');

//Create an instance from a binary file
$data = file_get_contents('my-image.jpg');

$image = Image::create($data);

//You can use also the direct functions:
$image = Image::createFromString($data);
$image = Image::createFromFile($file);

//Arguments: ($width, $height, $x = 'center', $y = 'middle');

$image->crop(200, 300); //Crops the image to 200x300px
$image->crop(200, 300, 'left', 'top'); //Crops the image to 200x300px starting from left-top
$image->crop(200, 300, 20, '50%'); //Crops the image to 200x300px starting from 20px (x) / 50% (y)
$image->crop('50%', '50%'); //Crops the image to half size

//Arguments: ($width, $height = 0, $enlarge = false)

$image->resize(200, 300); //Resizes the image to max size 200x300px (keeps the aspect ratio. If the image is lower, don't resize it)
$image->resize(800, 600, 1); //Resizes the image to max size 800x600px (keeps the aspect ratio. If the image is lower enlarge it)
$image->resize(800); //Resizes the image to 800px width and calculates the height maintaining the proportion.

//Arguments: ($width, $height, $x = 'center', $y = 'middle')

$image->resizeCrop(200, 300); //Resizes and crops the image to this size.

$image->rotate(90); //Rotates the image 90 degrees
$image->autoRotate(); //Rotates the image according its EXIF data.

$image->format('png');

$image->save('my-new-image.png');

//Overwrite the image (only if has been loaded from a file)
$image->save();

$image->transform('resize,200,300|format,png');

$image->show();

$image->getWidth();
$image->getHeight();
$image->getMimeType();

$image->getString(); //Returns the image in a string

$image->setBackground(array(255, 255, 255)); //Set a default background used in some transformations (for example, convert a transparent png to jpg)
$image->getExifData();
$image->setCompressionQuality(80); //Define the image compression quality for jpg images

use Imagecow\Image;

$operations = Image::getResponsiveOperations($_COOKIE['Imagecow_detection'], $_GET['transform']);

$image = Image::create();

$image->load($_GET['img'])->transform($operations)->show();

use Imagecow\Utils\IconExtractor;

$icon = new IconExtractor('favicon.ico');

//Gets the better image from the icon (quality = color_depth + (width * height))
$image = $icon->getBetterQuality();

//Do imagecow stuff
$image->resize(100)->save('my-image.png');

use Imagecow\Utils\SvgExtractor;

$svg = new SvgExtractor('image.svg');

//Gets the image
$image = $svg->get();

//Now you can execute the imagecow methods:
$image->resize(200)->format('jpg')->save('image.jpg');
javascript
Imagecow.cookie_seconds = 3600*24;
Imagecow.cookie_name = 'Imagecow_detection';
Imagecow.cookie_path = '/';

img.php?img=my_picture.png&transform=resizeCrop,800,600;max-width=400:resize,400