PHP code example of siaoynli / laravel-images
1. Go to this page and download the library: Download siaoynli/laravel-images 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/ */
siaoynli / laravel-images example snippets
php artisan vendor:publish --provider="Siaoynli\Image\ImageServiceProvider"
use Siaoynli\Upload\Facades\Upload;
use Siaoynli\Image\Facades\Image;
//upload
$info=Upload::do()
... //if upload success
//图片源文件存储在public目录
//使用相对路径
$filename = $info["url"];
Image::file('.'.$filename)->resize(1500)->save();
////使用绝对路径的文件
$filename = public_path($info["url"]);
Image::file($filename)->resize(1500)->save();
//thumb
Image::file($filename)->resize()->water()->save()
//small image
$small=Image::file($filename)->small()
//resize
Image::file($filename)->resize()->save()
//crop center
Image::file($filename)->crop()->save()
//water
Image::file($filename)->water()->save()
Image::file($filename)->water(public_path("/water/logo.png","bottom-right",20,20)->save("",80)
//压缩图片
Image::file(storage_path("app" . $filename))->resize(1500)->save();
//源文件存储到storage里,打水印和生成小图在 public 目录
Image::file(storage_path("app".$filename))->crop()->small($small_filename,150);
Image::file(storage_path("app".$filename))->resize()->water()->save(public_path($filename));
//存储为其他文件
$new_filename=storage_path($filename);
Image::file($filename)->water()->save($new_filename,90)