Skip to content

Commit

Permalink
Add option to disable blade iamge crop
Browse files Browse the repository at this point in the history
  • Loading branch information
dnabeast committed Nov 1, 2024
1 parent ddf761c commit a36cacb
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build
composer.lock
docs
vendor
.idea
coverage
bladeimagecrop.sublime-project
bladeimagecrop.sublime-workspace
2 changes: 2 additions & 0 deletions .idea/BladeImageCrop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/blade.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .phpunit.result.cache

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ The background builder can also be over written. Currently it takes the images a
If you wanted to (for instance) change this to load the same loading image you can write your own builder and swap it in with the config.

## Troubleshooting
**Is the site crashing and you're freaking out?**
Sometimes a weird file get through. I've tried my best to get rid of potential crashes but I can never underestimate the ingenuity of fools. If you need to turn off the process there is a config option.
```
'enabled' => env('BLADE_CROP_ENABLED', false),
```
or set it in your .env
```
BLADE_CROP_ENABLED=false
```

**Are you getting this error?**
```
syntax error, unexpected end of file, expecting "elseif" or "else" or "endif"
Expand Down
1 change: 1 addition & 0 deletions config/bladeimagecrop.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [
'enabled' => env('BLADE_CROP_ENABLED', true),
'disk' => 'public',
'offset_x' => 50, // percentage
'offset_y' => 50,
Expand Down
1 change: 1 addition & 0 deletions src/HoldImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function path(){
}

public function file(){

$extension = strtolower($this->src->explode('.')->last());
$formattedFileName = $this->src->slug.'.'.$extension;
// if file exists then return it
Expand Down
8 changes: 6 additions & 2 deletions src/View/Components/Img.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DNABeast\BladeImageCrop\ImageProps;
use DNABeast\BladeImageCrop\Source;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\View\Component;


Expand Down Expand Up @@ -34,6 +35,10 @@ public function __construct($src, $width=null, $properties=null, $sources=null)
*/
public function render()
{
if (!config('bladeimagecrop.enabled', true)){
return '<img src="'.$this->image->file().'" />';
}


return function (array $data){
$build = $this->build();
Expand All @@ -47,7 +52,6 @@ public function render()

public function build(){

$format = config('bladeimagecrop.build_classes');
$options = [
'src' => $this->image->file(),
'format' => array_keys(config('bladeimagecrop.build_classes'))[count(config('bladeimagecrop.build_classes'))-1],
Expand All @@ -60,7 +64,7 @@ public function build(){
$defaultImageSrc = explode(" ", $lines)[0];

if (config('bladeimagecrop.backgrounds')){
$backgroundLocation = 'blade_image_crop_holding/'.str($defaultImageSrc)->after('blade_image_crop_holding');
$backgroundLocation = 'blade_image_crop_holding/'.Str::of($defaultImageSrc)->after('blade_image_crop_holding');
$backgroundString = (new Background($backgroundLocation))->render();
}

Expand Down
4 changes: 4 additions & 0 deletions src/View/Components/Pic.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function __construct($src, $width=null, $properties=null)
*/
public function render()
{
if (!config('bladeimagecrop.enabled', true)){
return '<img src="'.$this->src.'" />';
}

return function (array $data){
$attributes = $data['attributes']->toHtml();
$propertyString = is_string($this->properties)?$this->properties:"[".implode(",", $this->properties)."]";
Expand Down
3 changes: 3 additions & 0 deletions src/View/Components/Sources.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function __construct($src, $properties, $media = null, $sizes = null)
*/
public function render()
{
if (!config('bladeimagecrop.enabled', true)){
return '';
}
return $this->build();
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/ImgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ function turn_sources_off_and_dont_see_srcset_at_all(){
$result->assertSee($expected, false);
}


}

0 comments on commit a36cacb

Please sign in to comment.