承接 gnahotelsolutions/image-cacher 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gnahotelsolutions/image-cacher

Composer 安装命令:

composer require gnahotelsolutions/image-cacher

包简介

Creates a resized or cropped version of the image in the cache directory

README 文档

README

Latest Version on Packagist Build status Quality Score Total Downloads

With this package you can create smaller versions of the same image to optimize user's transfer data. What's the point of downloading a 3000x3000 image on a 200x200 thumbnail? This package is very helpful when dealing with responsive images

Installation

You can install the package via composer:

composer require gnahotelsolutions/image-cacher

Usage

use GNAHotelSolutions\ImageCacher\Cacher;
use GNAHotelSolutions\ImageCacher\Image;

// Image located in public/img/hotel/rooms/double-room.jpg
$image = new Image('hotel/rooms/double-room.jpg', 'img');

$resized = (new Cacher())->resize($image, 1920, 1080); // Get a smaller version of the image or the same if the size is smaller.

$cropped = (new Cacher())->crop($image, 1920, 1080); // Get a cropped version of the image.

Generating a thumbnail

<?php 
$cacher = new Cacher();
$image = new Image('hotel/rooms/double-room.jpg', 'img'); 
?>

<img src="<?= $cacher->crop($image, 200, 200)->getOriginalName(); ?>" class="thumbnail">

Combining with srcset attribute

<?php 
$cacher = new Cacher();
$image = new Image('hotel/rooms/double-room.jpg', 'img'); 
?>

<img src="<?= $cacher->crop($image, 800, 600)->getOriginalName(); ?>"
     srcset="<?= $cacher->crop($image, 400, 280)->getOriginalName(); ?> 400w,
             <?= $cacher->crop($image, 800, 600)->getOriginalName(); ?> 800w"
     sizes="(max-width: 480px) 400px), 800px"
>

Using with Laravel

The package comes with a Facade you can use on your Laravel projects. Use the configuration file to tell where the cache path and the images root path are.

First of all, publish the package configuration file:

php artisan vendor:publish --provider="GNAHotelSolutions\ImageCacher\Adapters\Laravel\ImageCacherServiceProvider"

Adapt the config/image-cacher.php file variables to your needs. Default ones works well with a standard Laravel app.

<img src="{{ ImageCacher::crop('hotel/rooms/double-room.jpg', 800, 600)->getOriginalName() }}">

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email dllop@gnahs.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 6.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 5
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固