PHPackages                             dietercoopman/smart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. dietercoopman/smart

ActiveLibrary[Templating &amp; Views](/categories/templating)

dietercoopman/smart
===================

This packages enables the ability to serve file streams in a smart way

v2.0(1y ago)2387.5k20[1 PRs](https://github.com/dietercoopman/smart/pulls)MITPHPPHP ~7.2|~8CI passing

Since Sep 14Pushed 1y ago4 watchersCompare

[ Source](https://github.com/dietercoopman/smart)[ Packagist](https://packagist.org/packages/dietercoopman/smart)[ Docs](https://github.com/dietercoopman/smart)[ GitHub Sponsors](https://github.com/dietercoopman)[ RSS](/packages/dietercoopman-smart/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (29)Used By (0)

[![smart image manipulation](https://camo.githubusercontent.com/b4434448235dbe7ad34412f01574db830b9471dfa19e39c8027abb3e97e64b05/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f736d6172742e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d646965746572636f6f706d616e253246736d617274267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d426c6164652b636f6d706f6e656e74732b666f722b656173792b696d6167652b6d616e6970756c6174696f6e2b616e642b66696c652b646f776e6c6f616473266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/b4434448235dbe7ad34412f01574db830b9471dfa19e39c8027abb3e97e64b05/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f736d6172742e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d646965746572636f6f706d616e253246736d617274267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d426c6164652b636f6d706f6e656e74732b666f722b656173792b696d6167652b6d616e6970756c6174696f6e2b616e642b66696c652b646f776e6c6f616473266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![Latest Version on Packagist](https://camo.githubusercontent.com/59f08efdc54797b9e0d993fe6fd2a8ef6c031ec16cdf66a461ff34efd287bf45/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646965746572636f6f706d616e2f736d6172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dietercoopman/smart)[![Downloads](https://camo.githubusercontent.com/33b518f66dc5e00ac8f9cf5ab3b3c03d9024f4fe5b49576b4bed9a5b0873dab5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646965746572636f6f706d616e2f736d6172742e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/33b518f66dc5e00ac8f9cf5ab3b3c03d9024f4fe5b49576b4bed9a5b0873dab5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646965746572636f6f706d616e2f736d6172742e7376673f7374796c653d666c61742d737175617265)

Blade components for easy image manipulation and file downloads
===============================================================

[](#blade-components-for-easy-image-manipulation-and-file-downloads)

This package makes it possible to

- **serve images** from anywhere, this might be a public path , a private path or a Laravel disk
- **resize images** not only by defining height and width in the html image tag but by really resizing the content that is passed to the browser
- **apply templates** to images, change the settings for all images from one place
- automatically **cache** your images
- apply the **full intervention/image API** to an image
- **download files** from anywhere, this might be a public path , a private path or a Laravel disk
- use **smart-div** to add background images to div blocks

Typical use case
----------------

[](#typical-use-case)

### For smart image

[](#for-smart-image)

Serving images that are stored wherever you want, changing the size and look&amp;feel of an image without changing the original source. So you can use 1 image to once serve them for example grey on an overview page, but full color on a detail page.

### For smart download

[](#for-smart-download)

Downloading files that are stored wherever you want this can be your storage folder a Laravel disk or a https path

### For smart div

[](#for-smart-div)

Sometimes you have to add background images to div blocks, this can be achieved with smart-div. You can apply templates to the background images.

Watch me explaining what smart is on YouTube
--------------------------------------------

[](#watch-me-explaining-what-smart-is-on-youtube)

[![Schermafbeelding 2021-12-12 om 15 26 36](https://user-images.githubusercontent.com/4672752/145716421-cd75f419-0478-4f14-9522-703c2c76c84f.png)](https://www.youtube.com/watch?v=XuHM_9lhClE)

Installation
------------

[](#installation)

You can install the package via composer

```
composer require dietercoopman/smart
```

you can optionaly publish the config file if you want to use templates or change some settings ( see advanced usage with templates )

```
php artisan vendor:publish --tag=smart-config
```

Smart Image
===========

[](#smart-image)

Full example
------------

[](#full-example)

In this example the images are stored on S3. We want the images to be served all grey and at the same height, but also rotated 15 degrees. They are encoded as webp and given a good name, search engines will love them, all with 1 smart tag.

[![overview](https://user-images.githubusercontent.com/4672752/145693397-f960d88b-dc22-40f2-8699-e0351f6db632.png)](https://user-images.githubusercontent.com/4672752/145693397-f960d88b-dc22-40f2-8699-e0351f6db632.png)

The blade component
-------------------

[](#the-blade-component)

Smart provides you with a **blade component** as replacement for the normal `` html tag. You can pass in all default html attributes like the `class` tag they will be passed to the rendered html.

The attributes
--------------

[](#the-attributes)

### src

[](#src)

Specify the source of your image with `src`, this can be a https path, or a location on your server ( like /mnt/images ) or a Laravel disk to unlock serving images from S3, Dropbox or other custom filesystem.

### data-disk

[](#data-disk)

With this `data-disk` attribute you tell smart on which Laravel disk the src specified can be found.

### data-src

[](#data-src)

Specify the source as exposed to the browser with `data-src`. That is the source as shown in the rendered html, so you can expose friendly names to end users or search engines

### data-template

[](#data-template)

Specify the template to apply with `data-template` ( see advanced usage with templates ) to apply a pre-configured template to your images.

Examples
--------

[](#examples)

### Base example

[](#base-example)

This example will **serve a file that is stored in the storage folder**

```

```

### Loading images from Laravel disks

[](#loading-images-from-laravel-disks)

This example loads an image from a S3 compatible Laravel disk with `data-disk`

```

```

### Resizing images

[](#resizing-images)

This example will **serve a file that is stored in the storage folder** and **resize it** to 400px ( real file resize ! ) maintaining the aspect ratio.

```

```

### Changing the name of the served content

[](#changing-the-name-of-the-served-content)

The default name of the served images is a cache key, if you want to give it a more friendly name you can specify it with `data-src`

```

```

### Using templates

[](#using-templates)

With templates you can apply a predefined set of settings to your images. Typically handy if you are using images in several places of for example an e-commerce site.

```

```

Caching
-------

[](#caching)

The images are cached with the intervention/image cache. Default, the package will generate a key to store the images in the cache. This key will be used to build the src of the file, making it possible for browsers to cache the image. This key is random generated, but you can override it if you want a more descriptive name for your images ( see `data-src` ) .

[![cache example](cache.png)](cache.png)

Advanced usage with templates
-----------------------------

[](#advanced-usage-with-templates)

Via the `data-template`attribute you can specify which template your image should use. The templates are configurable in the `config/smart.php` config file.

Here's the default config

```
