Download the PHP package peterujah/nano-image without Composer

On this page you can find all versions of the php package peterujah/nano-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package nano-image

NanoImage

A lightweight PHP library for everyday image manipulation.
Resize, crop, rotate, filter, convert, and save images with a simple, dependency-free API powered by PHP's GD extension.

PHP 8.0 and later No third-party dependencies Powered by GD MIT License

Overview

NanoImage is a lightweight PHP image library built on the GD extension. It provides common image operations, including resizing, cropping, rotating, applying filters, and converting between supported formats.

Images can be displayed directly, returned as binary data, or saved to a file. NanoImage also handles transparency, supports safe file saving, and checks which image formats are available in the current GD installation.

Features

Feature Description
Resize and Scale Resize images with optional aspect ratio preservation.
Crop Crop an image to a specified area.
Rotate and Flip Rotate images and flip them horizontally or vertically.
Filters and Blur Apply image filters and blur effects.
Format Conversion Convert images to supported output formats.
Flexible Output Display images, return binary data, or save them to a file.
Transparency Preserve transparency in supported formats or flatten transparent areas when needed.
Safe File Saving Write to a temporary file before replacing the destination, helping prevent partial files and preserve existing files when saving fails.
Format Support Checks Check which image formats the current GD installation can read or write.

Requirements

Requires PHP and the GD extension. Support for individual image formats depends on the installed PHP and GD build.

Requirement Purpose
PHP 8.0 or later Required PHP version.
GD extension (ext-gd) Required for image processing.
GD format support WebP, AVIF, and other format support depends on the installed GD build.
EXIF extension (ext-exif) Required only for read/write EXIF metadata

Supported Image Formats

Format Extension Transparency
JPEG .jpg, .jpeg Flattened onto white
PNG .png Preserved
GIF .gif Supported, subject to GD limitations
WebP .webp Preserved when supported
BMP .bmp Flattened onto white
AVIF .avif Preserved when supported

See Supported Formats for format detection and runtime availability details.


Installation

Quick start


Loading

Loading a new image replaces (and frees) the previous one. Images that would not fit in PHP's memory_limit are rejected up front with an UnsupportedImageException instead of crashing PHP.

Resizing

Cropping, rotating and flipping

Rotating by a multiple of 90 degrees keeps every pixel. Other angles enlarge the canvas; with no background colour the corners are transparent (and saved white for JPEG/BMP).


Filters and blur

If GD rejects a queued filter (an unknown constant or missing arguments), the save fails and returns false; nothing is written.

contrast() flips GD's inverted sign for you. The raw filter(IMG_FILTER_CONTRAST, ...) does not. blur($range, $argument): $range is the number of blur passes; $argument is kept only for backward compatibility and has no effect, because GD's Gaussian blur takes no strength value. Blurred images come out slightly brighter (the original smoothing step adds brightness).


Output

The output format follows the extension you save to (save()) or the extension you pass (saveAs()). toString(), get() and display() use the source image's format.


Save options

$mode Behaviour
NanoImage::DEFAULT Use the name as given; an existing file is replaced, but only after the new file is complete.
NanoImage::THUMBNAIL Append the size: photo.jpg -> photo-360x200.jpg.
NanoImage::TIMESTAMP Append the date and time: photo-13-10-26-22-46-00.jpg (a counter is added if the name exists).

Supported formats

Format Read Write Transparency kept
JPEG (jpg, jpeg) yes yes no, flattened on white
PNG yes yes yes
GIF yes yes on/off only
WebP if GD has WebP if GD has WebP yes
AVIF if GD has AVIF (PHP 8.1+) if GD has AVIF yes
BMP yes yes no, flattened on white

Check what your server supports with print_r(gd_info());. A format GD cannot decode throws UnsupportedImageException when loading; one it cannot encode makes the save return false.


Metadata (EXIF)

GD never copies metadata into the images it writes, so every saved image is already stripped; removeExif() is simply a clearly named shortcut for save($path, NanoImage::DEFAULT, 100).

addExif() and setExif() need an exif_write_data() function, which standard PHP does not provide. Without one they return false and save nothing.


Method reference

Method Returns Notes
__construct($source = null) file path or raw image data
open(string $file) self throws UnsupportedImageException
load(string $data) self throws UnsupportedImageException
getWidth(), getHeight() int current size in pixels
getMimeType() string MIME type of the source
getExifData() array Read Image exift data
getExtension() string extension used by the last save
getSavedPath() string file written by the last successful save
isResized() bool whether resize() was called
setWidth(int), setHeight(int), aspectRatio(bool) self queued
resize(int $w, int $h, bool $ratio = false) self queued
scale(float $factor) self immediate
crop(int $x, int $y, int $w, int $h) self immediate
rotate(float $degrees, $background = null) self immediate
flip(int $mode = FLIP_HORIZONTAL) self immediate
grayscale(), brightness(int), contrast(int) self queued
filter(int $filter, ...$args), filters(array) self queued
blur(int $range = 5) self immediate
save(), saveAs(), replace(), removeExif() bool write a file
toString(int $quality = 100) string encoded bytes, '' on failure
get(), display() bool write to output (display() adds the header)
addExif(), setExif() bool need exif_write_data()
remove() self delete the opened file
free() void release memory

Constants: JPG, JPEG, PNG, GIF, WEBP, BMP, AVIF, DEFAULT, THUMBNAIL, TIMESTAMP, FLIP_HORIZONTAL, FLIP_VERTICAL, FLIP_BOTH.


How It Works


Limitations

Testing


All versions of nano-image with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-gd Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package peterujah/nano-image contains the following files

Loading the files please wait ...