Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsklopstra committed Mar 14, 2022
0 parents commit 943acec
Show file tree
Hide file tree
Showing 18 changed files with 3,131 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: larsklopstra
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
/.idea
/.vscode
/.php-cs-fixer.cache
40 changes: 40 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/routes',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Flowframe <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Laravel Drift

Optimize images on the fly.

## Installation

You can install the package via composer:

```
composer require flowframe/laravel-drift
```

## Usage

Simply install the package, and register a configuration in `AppServiceProvider@boot`:

```php
use Flowframe\Drift\Config;
use Flowframe\Drift\DriftManager;
use Flowframe\Drift\CachingStrategies\FilesystemCachingStrategy;

/** @var DriftManager $drift */
$drift = app(DriftManager::class);

$drift->registerConfig(new Config(
name: 'my-config-name', // Will be used in the slug
filesystemDisk: 'filesystems-disk-name', // Local, public or s3 for example
cachingStrategy: FilesystemCachingStrategy::class, // Create your own or use the defaults like FilesystemCachingStrategy or NullCachingStrategy
));
```

### Image URLs

To generate an image URL use the `\Flowframe\Drift\UrlBuilder` like so:

```php
use Flowframe\Drift\UrlBuilder;

/** @var UrlBuilder $builder */
$builder = app(UrlBuilder::class);

$image = $builder->url('my-config-name', 'example.png', [
'resize' => [1920, 1080],
'encode' => 'webp', // The fallback encoding will be webp
]);
```

You can use most of [Intervention Image's](https://image.intervention.io/v2/usage/overview#editing-images) methods, simply use the method name as key and set the argument as value. Have more than one argument? Use an array instead like in the example above.

### Blade Component

```blade
<x-drift::image
class="w-full aspect-[16/9] object-cover"
config="my-config-name"
path="example.png"
:manipulations="[
'encode' => ['jpeg', 50],
'greyscale' => true,
]"
/>
```
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "flowframe/laravel-drift",
"type": "library",
"license": "MIT",
"homepage": "https://github.com/flowframe/laravel-drift",
"autoload": {
"psr-4": {
"Flowframe\\Drift\\": "src"
}
},
"authors": [
{
"name": "Lars Klopstra",
"email": "[email protected]"
}
],
"require": {
"php": "^8.0",
"illuminate/support": "^9.4",
"intervention/image": "^2.7",
"illuminate/http": "^9.4"
},
"extra": {
"laravel": {
"providers": [
"Flowframe\\Drift\\DriftServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Loading

0 comments on commit 943acec

Please sign in to comment.