Php_imagick Program Examples
1. Create a thumbnail image and display it
<?php
Header (' Content-type:image/jpeg ');
$image = new Imagick (' image.jpg ');
If 0 is provided as a width or height parameter,//aspect ratio is maintained
$image->thumbnailimage (100, 0);
Echo $image;
?>
2. Create a thumbnail in a directory and save
<?php
$images = new Imagick (Glob (' images/*. JPG '));
foreach ($images as $image) {
Providing 0 forces thumbnailimage to maintain aspect ratio
$image->thumbnailimage (1024,0);
}
$images->writeimages ();
?>
3. Animated image of the thumbnail gif
<?php
/* Create A new Imagick object and read in GIF */
$im = new Imagick ("Example.gif");
/* Resize All frames */
foreach ($im as $frame) {
/* 50x50 Frames */
$frame->thumbnailimage (50, 50);
/* Set the virtual canvas to correct size */
$frame->setimagepage (50, 50, 0, 0);
}/* Notice writeimages instead of writeimage * *
$im->writeimages ("Example_small.gif", true);
?>
The method of using Php_imagick to realize the retro effect
Look first.
Retro effect Show
To achieve the above results, we first use Photoshop to implement the following steps.
Open Original
New layer, with color #c0ffff fill, opacity set to 44%, layer blending mode to soft light
New layer, with color #000699 fill, opacity set to 48%, layer blending mode is excluded
Merging layers
With PHP code, you just need to follow the above steps to achieve, the code is as follows:
Open picture
$im = new Imagick ('./hebe.jpg ');
New layer, with color ' #C0FFFF ' Fill, opacity set to ' 44% '
$layer = new Imagick ();
$layer->newimage ($im->getimagewidth (), $im->getimageheight (), ' #C0FFFF ');
$layer->setimageopacity (0.44);
Overlay to original, layer blending mode ' soft light '
$im->compositeimage ($layer, imagick::composite_softlight, 0, 0);
New layer, with color ' #000699 ' padding, opacity set to ' 48% '
$layer = new Imagick ();
$layer->newimage ($im->getimagewidth (), $im->getimageheight (), ' #000699 ');
$layer->setimageopacity (0.48);
Overlay to original, layer blending mode ' exclude '
$im->compositeimage ($layer, imagick::composite_exclusion, 0, 0);
Complete!
$im->writeimage ('./vintage.jpg ');
A new addition to Laravel was the ability to specify the creation of a resourceful controller when you were creating a new M Odel through Artisan. This means your can pass a-c or--controller flag to Make:model:
PHP artisan make:model Post--controller Laravel Image Dimensions Validation
New in Laravel v5.3 are the ability to validate image files to ensure they meet certain dimensions and through the Validato R This can is setup with a string format:
' Avatar ' = ' DIMENSIONS:MIN_WIDTH=100,MIN_HEIGHT=200,RATIO=3/2 '
V5.3.19 This can specified through a fluent syntax similar to unique and exists validation rules:
Rule::d imensions ()->minwidth (+)->minheight (+)->ratio (3/2) Laravel Validation in and not_in
The in and not_in validation received the ability to pass an array.
Previous in:php,laravel,...//New rule::in ([' php ', ' laravel '])
Then the same for not_in
Previous not_in:php,laravel,...//New rule::notin ([' php ', ' laravel '])
Either style is valid and the new object-based style parses the to the old. Whichever suits your app.
After Validation Hook
Now your controllers can has a new Withvalidator method so can easily call any hooks after validation:
protected function Withvalidator ($validator) {$validator->after (function ($validator) {if ($this- Somethingelseisinvalid ()) {$validator->errors ()->add (' field ', ' Something is wrong with this field! ');}); }
Previously had to manually setup the $validator = Validator::make () before your could use a after hook which meant Lost the ability to utilize the validatesrequests trait.
Upgrading Laravel
To get this latest version all need to does is run composer update and you can find a complete list of changes in the CH Angelog
How does Php_imagick achieve the retro effect?