1. Go to this page and download the library: Download czim/file-handling 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/ */
czim / file-handling example snippets
// Set up a storage implementation (for your framework of choice), and a PSR-11 container implementation.
/** @var \Czim\FileHandling\Contracts\Storage\StorageInterface $storage */
/** @var \Psr\Container\ContainerInterface $container */
$sourcePath = 'storage/input-file-name.jpg';
// Source File
$helper = new \Czim\FileHandling\Support\Content\MimeTypeHelper;
$interpreter = new \Czim\FileHandling\Support\Content\UploadedContentInterpreter;
$downloader = new \Czim\FileHandling\Support\Download\UrlDownloader($helper);
$validator = new \Czim\FileHandling\Support\Download\UriValidator();
$factory = new \Czim\FileHandling\Storage\File\StorableFileFactory(
$helper,
$interpreter,
$downloader,
$validator
);
$file = $factory->makeFromLocalPath($sourcePath);
// Handler
$strategyFactory = new \Czim\FileHandling\Variant\VariantStrategyFactory($container);
$strategyFactory->setConfig([
'aliases' => [
'resize' => \Czim\FileHandling\Variant\Strategies\ImageResizeStrategy::class,
'autoOrient' => \Czim\FileHandling\Variant\Strategies\ImageAutoOrientStrategy::class,
],
]);
$processor = new \Czim\FileHandling\Variant\VariantProcessor($factory, $strategyFactory);
$handler = new \Czim\FileHandling\Handler\FileHandler($storage, $processor);
$handler->process($file, new Target($file->path()), [
'variants' => [
'tiny' => [
'autoOrient' => [],
'resize' => [
'dimensions' => '30x30',
],
],
'orient' => [
'autoOrient' => [
'quiet' => false,
],
],
],
]);
// Storage
$storage = new \Czim\FileHandling\Storage\Laravel\LaravelStorage(
\Storage::disk('testing'),
true,
url('testing')
);
// If you're using a Laravel version that does not have a PSR-11 compliant container yet:
$container = new \Czim\FileHandling\Support\Container\LaravelContainerDecorator(app());
app()->bind(\Imagine\Image\ImagineInterface::class, \Imagine\Gd\Imagine::class);
$container = new \Czim\FileHandling\Support\Container\SimpleContainer;
$container->registerInstance(
\Czim\FileHandling\Variant\Strategies\ImageResizeStrategy::class,
new \Czim\FileHandling\Variant\Strategies\ImageResizeStrategy(
new \Czim\FileHandling\Support\Image\Resizer(
new \Imagine\Gd\Imagine
)
)
);
$container->registerInstance(
\Czim\FileHandling\Variant\Strategies\ImageAutoOrientStrategy::class,
new \Czim\FileHandling\Variant\Strategies\ImageAutoOrientStrategy(
new \Czim\FileHandling\Support\Image\OrientationFixer(new \Imagine\Gd\Imagine)
)
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.