Giter Club home page Giter Club logo

php-cloudflare-image-resizing's Introduction

PHP Cloudflare Image

GitHub Workflow Status (master) Total Downloads Latest Version License


A PHP package to generate Cloudflare Image Resizing URLs. based on Cloudflare Image Resizing.

โšก๏ธ Installation

Requires PHP 8.2+

composer require aneeskhan47/php-cloudflare-image-resizing

โ“ How it works

Cloudflare Image Resizing is a feature that allows you to resize, crop, and convert images by simply changing the URL of the image. This is done by adding a set of image transformation parameters to the URL of the image, which Cloudflare will then use to generate a new image on the fly.

So just by adding /cdn-cgi/image/ to the beginning of the URL, you can utilize Cloudflare's image resizing feature.

You can convert and resize images by requesting them via a specially-formatted URL. This way you do not need to write any code, only change HTML markup of your website to use the new URLs.

For more information, please see the Cloudflare Image Resizing documentation.

This package provides a fluent API to generate Cloudflare Image Resizing URLs.


๐Ÿš€ Usage

Generating a URL without any transformations

use AneesKhan47\CloudflareImageResizing\CFImageResizing;

$url = 'https://example.com/uploads/2023/image.jpg';

$image = CFImageResizing::make($url)->build();

// output: 
// https://example.com/cdn-cgi/image/format=auto/uploads/2023/image.jpg

// note: format=auto is added by default to the URL as it is required 
// by Cloudflare to have atleast one transformation applied.

Generating a URL with transformations

use AneesKhan47\CloudflareImageResizing\CFImageResizing;

$url = 'https://example.com/uploads/2023/image.jpg';

$image = CFImageResizing::make($url)
                        ->width(300)
                        ->height(300)
                        ->webp()
                        ->quality(80)
                        ->build();

// output: 
// https://example.com/cdn-cgi/image/width=300,height=300,format=webp,quality=80/uploads/2023/image.jpg

Available transformations

Please see the available transformations here.


๐Ÿงช Testing

๐Ÿงน Keep a modern codebase with Pint:

composer lint

โœ… Run refactors using Rector

composer refacto

โš—๏ธ Run static analysis using PHPStan:

composer test:types

โœ… Run unit tests using PEST

composer test:unit

๐Ÿš€ Run the entire test suite:

composer test

๐Ÿ“ Changelog

Please see CHANGELOG for more information on what has changed recently.


๐Ÿค Contributing

Please see CONTRIBUTING for details.


๐Ÿ”’ Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.


๐Ÿ™Œ Credits


๐Ÿ“œ License

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


๐Ÿ”ง Skeleton PHP Boilerplate

This package was generated using the Skeleton PHP by Nuno Maduro.

php-cloudflare-image-resizing's People

Contributors

aneeskhan47 avatar

Stargazers

Simon avatar pumping balls since 2000 avatar  avatar Osama Kamel avatar BLK LUV [org] avatar  avatar

Watchers

 avatar

php-cloudflare-image-resizing's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.