Download the PHP package thecyrilcril/imagekit-laravel-client without Composer

On this page you can find all versions of the php package thecyrilcril/imagekit-laravel-client. 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 imagekit-laravel-client

ImageKit Laravel Client

A Laravel-native client for the ImageKit API, built on Illuminate\Http\Client. Typed requests, typed results, typed exceptions. Http::fake() intercepts every request it makes.

It exists so that thecyrilcril/laravel-imagekit no longer needs the imagekit/imagekit SDK, which pins Guzzle 7 and cannot be installed on Laravel 13 without -W. You can also use it on its own.

Status: pre-release. The Client boots, validates its configuration, and files()->upload(), files()->delete(), files()->list(), files()->lazy() and urls()->build() work end to end.

Requirements

Installation

The package ships Laravel Boost AI guidelines (resources/boost/guidelines/core.blade.php): run php artisan boost:install and select this package, and your coding agent learns the rules in this README without you writing them.

Add your credentials to .env:

Every config key reads from the environment:

Key Env Default
public_key IMAGEKIT_PUBLIC_KEY required
private_key IMAGEKIT_PRIVATE_KEY required
url_endpoint IMAGEKIT_URL_ENDPOINT required
transformation_position IMAGEKIT_TRANSFORMATION_POSITION path
http.timeout IMAGEKIT_HTTP_TIMEOUT 30 seconds
http.retries IMAGEKIT_HTTP_RETRIES 0

Resolving the Client with a missing credential, an unknown transformation_position, or a non-integer http.* value throws Thecyrilcril\ImageKitClient\Exceptions\InvalidConfiguration. You find out about a bad .env at boot, not at the first upload.

HTTP behaviour

Every request goes through Illuminate\Http\Client, so Http::fake() intercepts it in your tests. Management calls go to https://api.imagekit.io/v1, uploads to https://upload.imagekit.io/api/v1, both with HTTP Basic auth (private key as the user, empty password) and Accept: application/json.

Usage

Inject the contract, or use the facade. Both resolve the same singleton.

Exceptions

Every exception the package throws extends Thecyrilcril\ImageKitClient\Exceptions\ImageKitClientException. Catch that for "anything the Client can fail with", or a subclass to tell the failures apart:

Exception When Carries
InvalidConfiguration A credential is missing or a config value is malformed
ImageKitError (abstract) ImageKit answered with an error status; parent of the next three status, imageKitMessage, help; getMessage() is ImageKit responded with HTTP 400: <message>
RequestFailed Any 4xx/5xx other than 404 or 429 (after retries) as ImageKitError
NotFound A 404 as ImageKitError
RateLimited A 429 and no retry is left as ImageKitError, plus retryAfterMilliseconds
TransportError ImageKit could not be reached (after retries) The ConnectionException as getPrevious()
InvalidListRequest A ListRequest with a limit outside 1–1000 or a negative skip
UnexpectedResponse ImageKit answered 2xx with a body that is not what the docs promise (not a JSON listing, an asset with no type, a required field missing or malformed)
InvalidTransformation A Transformation key or value the URL builder cannot render
InvalidUrlRequest A URL request with no source, with both path and src, or with a signing option that does not fit (signed with src, expiresIn without signed, expiresIn ≤ 0)
InvalidUploadRequest An upload request that could never succeed: empty bytes, a data URI without data:, a URL that is not http(s), or an empty fileName

Uploading files

files()->upload() takes an UploadRequest and returns an UploadedFile. The content comes from one of three UploadSources: raw bytes (sent as the multipart file part), a base64 data: URI, or a public http(s) URL that ImageKit fetches itself. Every documented upload field is a named argument under its API name; a field left null stays off the wire so ImageKit applies its own default.

Wire rules, so nothing is sent in a form ImageKit misreads: booleans go as the words "true"/"false" (a raw false would leave as an empty field); tags and responseFields are comma-joined; customMetadata, extensions and transformation are JSON. The shapes of those three are ImageKit's own and pass through verbatim — see the upload API reference for the keys each accepts.

UploadedFile exposes every documented response field, typed. The fields ImageKit only sends when asked for through responseFields (tags, customCoordinates, isPrivateFile, isPublished, customMetadata, embeddedMetadata, metadata, selectedFieldsSchema) read as null, or as an empty list or map, when they were not asked for. Fields ImageKit adds later are ignored.

An upload ImageKit rejects throws RequestFailed with the status and ImageKit's message; an unreachable ImageKit throws TransportError; a 2xx whose body is not the documented shape throws UnexpectedResponse. Empty bytes, a data URI without the data: prefix, a URL that is not http(s), or an empty fileName throw InvalidUploadRequest before any request leaves.

Listing and searching files

files()->list() fetches one page of a listing as a FileListing; files()->lazy() walks every page for you. Both take a ListRequest whose properties are exactly the documented query parameters, with enums where ImageKit enumerates.

FileListing is Countable and iterable. items holds every entry in ImageKit's order (File and Folder objects, told apart by class or by ->type); files() and folders() return one kind.

File carries every documented field, typed: fileId, type (AssetType::File or FileVersion), name, filePath, url, thumbnail, fileType (image/non-image, kept as a string), mime, size, width, height, hasAlpha, tags, aiTags (AITag objects: name, confidence, source), customCoordinates, customMetadata, description, embeddedMetadata, selectedFieldsSchema, isPrivateFile, isPublished, versionInfo (id, name), createdAt, updatedAt (DateTimeImmutable), and for video duration, bitRate, audioCodec, videoCodec. A field ImageKit only sets for some files is null when absent; the list and object fields are empty instead. Folder carries folderId, name, folderPath, customMetadata, createdAt, updatedAt and type (AssetType::Folder). Fields this package does not know are ignored; a 2xx whose body is not a listing, or an asset missing a required field, throws UnexpectedResponse.

Paging

lazy() returns a LazyCollection of File|Folder. Nothing is sent until you consume it; each page is fetched when you reach it. Paging starts at the request's skip (default 0), moves by its limit (ListRequest::DEFAULT_PAGE_SIZE, 100, when not set), and stops on the first page shorter than that limit.

An error on any page (RequestFailed, RateLimited, TransportError, UnexpectedResponse) surfaces from the consumer loop.

Building URLs

urls()->build() turns a UrlRequest into a delivery URL. Pure string building, no HTTP.

A Transformation is a flat array. Its keys are friendly aliases (table below), ImageKit short codes (['w' => 200, 'e-bgremove' => true]), or raw, which passes its value through verbatim (no encoding) for syntax the map does not cover (layers, conditionals, a code newer than this package); in a signed URL, percent-encode a raw value yourself, since the signature covers the exact bytes. Any other key throws Thecyrilcril\ImageKitClient\Exceptions\InvalidTransformation, so a typo in a preset fails loudly instead of emitting a broken URL.

Alias Code Alias Code Alias Code
width w defaultImage di colorize e-colorize
height h named n distort e-distort
aspectRatio ar radius r aiRemoveBackground e-bgremove
crop c background bg aiRemoveBackgroundExternal e-removedotbg
cropMode cm border b aiChangeBackground e-changebg
focus fo rotation rt aiEdit e-edit
zoom z flip fl aiDropShadow e-dropshadow
x, y x, y blur bl aiRetouch e-retouch
xCenter, yCenter xc, yc trim t aiUpscale e-upscale
dpr dpr opacity o aiVariation e-genvar
quality q colorReplace cr page pg
format f contrastStretch e-contrast contentCredentials c2pa
lossless lo sharpen e-sharpen startOffset so
progressive pr unsharpMask e-usm endOffset eo
metadata md grayscale e-grayscale duration du
colorProfile cp shadow e-shadow videoCodec vc
density dn gradient e-gradient audioCodec ac
original orig streamingResolutions sr

The names imagekit/imagekit 4.0.2 accepted (rotate, effectSharpen, effectUSM, effectContrast, effectGray, effectShadow, effectGradient, and '-' as a value for a bare code) are also accepted, so presets written against it keep rendering the same URL.

Transformation position

Transformations go in the URL path by default (/tr:w-200/photo.jpg). ImageKit's newer SDKs default to the query string (?tr=w-200). Both render the same image, but the CDN caches by URL text, so this package keeps the path form to stay byte-identical with URLs already in the wild. Set transformation_position to query to opt in to the other form.

Faking the Client in your tests

ImageKitClient::fake() swaps the Client in the container for a fake that records uploads, deletions and listings and never sends a request. Anything that injects Contracts\Client, and the facade, get the fake from then on.

The fake answers as ImageKit would, without HTTP:

To test your own failure handling, tell the fake to reject uploads: every upload() then throws RequestFailed (HTTP 500) and the attempt is still recorded.

Combine it with Http::fake() and Http::assertNothingSent() to prove your code never reaches ImageKit.

Testing

License

MIT. See LICENSE.md.


All versions of imagekit-laravel-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
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 thecyrilcril/imagekit-laravel-client contains the following files

Loading the files please wait ...