GithubHelp home page GithubHelp logo

mwarcz / segami-php Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 232 KB

PHP library that allows you to edit image dimensions, convert image format, cache generated images, record last access to generated image in cache, remove images from cache that have not been used for long time, all based on image name.

License: MIT License

PHP 100.00%

segami-php's Introduction

Segami

Segami is simple PHP library that allows edit image dimensions, convert image format, cache generated images, record last access to generated image in cache, remove images from cache that have not been used for long time, all based on image suffix in name.

PHP version Packagist version MIT License

Key features

  • Convert image format
  • Create image crop
  • Resize image
    • Optional function that allows you to change size of image in the required dimensions and fill type (fill, contain, cover).
    • Example: sample.png@r200x100_cover.png, [email protected]
  • Set image quality/compression
  • Store generated images (cache)
    • Library allows storing generated images in cache directory for quick retrieval of generated image, as name of image precisely defines its properties.
    • Image filenames are normalized in background to avoid unnecessary duplication.
  • Automatic removal of long-term unused images from cache
    • Library provides functions for removing previously stored images to help clear disk space of images that have not been used for long time.
  • Limiters limiting names of required images
    • Optionally, it is possible to restrict image names that modify original image.
    • It is recommended to limit image names when storing to cache is enabled, so that potential attacker has difficult time attacking you.

Requirements

Installation

Segami library is available on Packagist and installing via Composer is recommended way to install it.

Just use the command in terminal:

composer require mwarcz/segami

Or manually add to composer.json file:

{
    "require": {
        "php": "^8.1",
        "mwarcz/segami": "dev-master"
    }
}

Note: Replace dev-master with specific version constraint. See Packagist for available versions.

Usage

Short example of possible basic use of library:

$segami = new Segami([
  // Selected path to dir with original images
  'path_to_original_images' => __DIR__ . '/original',
  // Selected path to dir with generated images
  'path_to_generated_images' => __DIR__ . '/generated',
  // Selected plugins for generating images
  'plugin' => [
    // CorePlugin is required minimum - enable core name parsing and image format conversion
    'core' => new CorePlugin(),
    // Optional ResizePlugin - enable/add possibility resize image
    'resize' => new ResizePlugin(),
    // Optional QualityPlugin - enable/add possibility quality image
    'quality' => new QualityPlugin(),
  ],
  // Selected limiter with rules for generated images
  'limiter' => new FreeImageLimiter(),
  // Selected image engine
  'image_factory' => new ImageImagickFactory(),
  // Selected logger for logging access to images
  'image_logger' => new ImageLoggerNone(),
]);

try {
  $segami->smartReturnImage($_GET['image'], isset($_GET['cache']));
} catch (\Throwable $e) {
  http_response_code(404);
}

Repository contains set of samples of various use case:

More detailed information about functions and use case of Segami library can be found in upcoming documentation.

License

Segami is licensed under MIT license.


TODO roadmap

See Czech version.

segami-php's People

Contributors

mwarcz avatar

Watchers

 avatar

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.