1. Go to this page and download the library: Download 68publishers/image-storage library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
68publishers / image-storage example snippets
use SixtyEightPublishers\ImageStorage\ImageStorageInterface;
/** @var ImageStorageInterface $storage */
# Create resource from local file or url:
$resource = $storage->createResourceFromFile(
$storage->createPathInfo('test/my-image.jpeg'),
__DIR__ . '/path/to/my-image.jpeg'
);
$storage->save($resource);
# Create resource from a file that is stored in storage:
$resource = $storage->createResource(
$storage->createPathInfo('test/my-image')
);
# Copy to the new location
$storage->save($resource->withPathInfo(
$storage->createPathInfo('test/my-image-2')
));
use SixtyEightPublishers\ImageStorage\ImageStorageInterface;
/** @var ImageStorageInterface $storage */
$pathInfo = $storage->createPathInfo('test/my-image');
if ($storage->exists($pathInfo)) {
echo 'source image exists!';
}
if ($storage->exists($pathInfo->withModifiers(['w' => 150]))) {
echo 'cached image with width 150 in JPEG (default) format exists!';
}
if ($storage->exists($pathInfo->withModifiers(['w' => 150])->withExtension('webp'))) {
echo 'cached image with width 150 in WEBP format exists!';
}
use SixtyEightPublishers\ImageStorage\ImageStorageInterface;
use SixtyEightPublishers\ImageStorage\Persistence\ImagePersisterInterface;
/** @var ImageStorageInterface $storage */
# delete all cached images only:
$storage->delete($storage->createPathInfo('test/my-image'), [
ImagePersisterInterface::OPTION_DELETE_CACHE_ONLY => TRUE,
]);
# delete cached images and source image:
$storage->delete($storage->createPathInfo('test/my-image'));
# delete only cached image with 200px width in PNG format
$storage->delete($storage->createPathInfo('test/my-image.png')->withModifiers(['w' => 200]));