php_imagick是怎麼實現複古效果的呢?

來源:互聯網
上載者:User

標籤:setimage   size   validator   tin   complete   asp   through   array   sam   

php_imagick程式樣本

1.建立一個縮圖並顯示出來

<?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.建立一個目錄下的縮圖,並儲存

<?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.縮減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);
?>

利用php_imagick實現複古效果的方法

先來看下


複古效果展示

要實現以上效果,我們先用Photoshop用以下步驟實現。

開啟原圖
建立圖層,使用顏色#C0FFFF填充後,不透明度設為44%,圖層混合模式為柔光
建立圖層,使用顏色#000699填充後,不透明設定為48%,圖層混合模式為排除
合并圖層

用PHP代碼,也就只需要按照以上步驟實現即可,代碼如下:

//開啟圖片
$im = new Imagick(‘./hebe.jpg‘);
//建立圖層,使用顏色`#C0FFFF`填充後,不透明度設為`44%`
$layer = new Imagick();
$layer->newImage($im->getImageWidth(), $im->getImageHeight(), ‘#C0FFFF‘);
$layer->setImageOpacity (0.44);
//疊加到原圖上,圖層混合模式為`柔光`
$im->compositeImage($layer, Imagick::COMPOSITE_SOFTLIGHT, 0, 0);
//建立圖層,使用顏色`#000699`填充後,不透明設定為`48%`
$layer = new Imagick();
$layer->newImage($im->getImageWidth(), $im->getImageHeight(), ‘#000699‘);
$layer->setImageOpacity (0.48);
//疊加到原圖上,圖層混合模式為`排除` 
$im->compositeImage($layer, Imagick::COMPOSITE_EXCLUSION, 0, 0);
//完成!
$im->writeImage(‘./vintage.jpg‘);

A new addition to Laravel is the ability to specify the creation of a resourceful controller when you are creating a new Model through Artisan. This means you 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 is the ability to validate image files to ensure they meet certain dimensions and through the validator this can be setup with a string format:

‘avatar‘ => ‘dimensions:min_width=100,min_height=200,ratio=3/2‘

Now in v5.3.19 this can be specified through a fluent syntax similar to unique and exists validation rules :

Rule::dimensions()->minWidth(100)->minHeight(100)->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 down into the old way. So you are free to use whichever suits your app.

After Validation Hook

Now your controllers can have a new withValidator method so you 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 you had to manually setup the $validator = Validator::make() before you could use an after hook which meant you lost the ability to utilize the ValidatesRequests trait.

Upgrading Laravel

To get this latest version all you need to do is run composer update and you can find a complete list of changes in the changelog

php_imagick是怎麼實現複古效果的呢?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.