承接 martijnvdb/php-image-resize 相关项目开发

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

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

martijnvdb/php-image-resize

Composer 安装命令:

composer require martijnvdb/php-image-resize

包简介

Simple library for resizing and converting images to different filetypes

关键字:

README 文档

README

This simple library allows you to resize and convert images to a different filetype. The supported filetypes are JPG, PNG, GIF and WebP. Animated GIF and WebP files are not supported.

Installation

You can install the package via composer:

composer require martijnvdb/php-image-resize

Usage

Add the composer autoloader to your application and create a new instance of the ImageResize class given the path to the source images as the first argument.

require __DIR__ . '/vendor/autoload.php';

use Martijnvdb\ImageResize\ImageResize;

$image = new ImageResize(__DIR__ . '/image-1.jpg');

Methods

Use the export() method to save the image to the given path. By default it will convert the source image to the given output filetype. In the following example it will convert the original JPG image to a WebP image.

$image = new ImageResize(__DIR__ . '/image-1.jpg');
$image->export(__DIR__ . '/resized/image-1.webp');

Using the setWidth() and setHeight() methods, you can set the maximum size the width and height of the exported image. By default it won't change the aspect ratio of the image. Therefore the image will be scaled up or down to fit within the given size constraints. You can use both the setWidth() and setHeight() methods when exporting an image, or just a single one.

$image = new ImageResize(__DIR__ . '/image-1.jpg');
$image->setWidth(500);
$image->setHeight(500);
$image->export(__DIR__ . '/resized/image-1.webp');

You can use the ignoreRatio() to ignore the aspect ratio of the source image and strech the exported image to the given width and height.

$image = new ImageResize(__DIR__ . '/image-1.jpg');
$image->setWidth(500);
$image->setHeight(500);
$image->ignoreRatio();
$image->export(__DIR__ . '/resized/image-1.webp');

The setQuality() method is used to change the quality of the exported image. It accepts a float between 0 and 1, with 0 being the worst and 1 being the best quality. The default is 0.9 and can only be used when exporting to JPG, PNG and WebP filetypes.

$image = new ImageResize(__DIR__ . '/image-1.jpg');
$image->setQuality(0.65);
$image->export(__DIR__ . '/resized/image-1.webp');

It is also possible to use the static get() method for easier method chaining.

$image = ImageResize::get(__DIR__ . '/image-1.jpg')
    ->setWidth(500)
    ->setHeight(500)
    ->setQuality(.8)
    ->ignoreRatio()
    ->export(__DIR__ . '/resized/image-1.webp');

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固