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

Related tags

Miscellaneous smart
Overview

Downloads

smart image manipulation

A blade component for easy image manipulation

Want to serve private hosted images without the need to code your own logic ? Want to resize your images before sending them to the browser, without extra coding ? Then smart might be your buddy !

This package makes it possible to

  • serve images that are not public accessible without coding
  • resize images without coding
  • resizing public hosted images without coding
  • automatically cache your images

Installation

You can install the package via composer:

composer require dietercoopman/smart

The blade component

Smart provides you with a blade component as replacement for the normal <img> html tag. You can pass in all html attributes , they will be applied. This example will serve a file that is not public accessible and resize it to 400px maintaining the aspect ratio.

<x-smart-image src="{{ storage_path('smart.png') }}" width="400px"/>

This will parse the image , cache it and serve to your browser

<img src="smart/7b5a22db93fd72ead9c5292182927ff2" width="400px">

It's also possible to handle public hosted files but changing the image size , so execute a real resize on the image stream and not only telling the browser to show it at other dimensions.

<x-smart-image src="https://raw.githubusercontent.com/dietercoopman/smart/main/tests/test.png" width="600px" />

smart example

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 a random generated but you can override it if you want a more descriptive name for your images.

This can be done by setting the data-src attribute for your smart image.

<x-smart-image src="{{ storage_path('smart.png') }}" data-src="branding.png" width="400px"/>

this will generate this html as output

<img src="smart/branding.png" width="600px">

Here you see the caching in action

cache example

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  •  <x-smart-image src=">

    syntax error, unexpected '=>' (T_DOUBLE_ARROW) (View: C:\OpenServer\domains\shop.loc\vendor\dietercoopman\smart\resources\views\components\smart-image.blade.php) C:\OpenServer\domains\shop.loc\vendor\dietercoopman\smart\src\Factories\HtmlFactory.php#12 Facade\Ignition\Exceptions\ViewException syntax error, unexpected '=>' (T_DOUBLE_ARROW) C:\OpenServer\domains\shop.loc\vendor\dietercoopman\smart\src\Factories\HtmlFactory.php#12

    opened by rudaovel 13
  • Default image

    Default image

    Is your feature request related to a problem? Please describe. I will always get 1 error if the photo doesn't exist

    image

    Describe the solution you'd like Please do a try catch or something to always return 1 default image (image can be white or have something like http://placehold.jp/150x150.png)

    Describe alternatives you've considered N/A

    Additional context N/A

    opened by tmtung144 2
  • alt attribute is missing space in front

    alt attribute is missing space in front

    Hi Dieter,

    first off thank you for this very interesting and promising package! I have just recently discovered it through Laravel News.

    For web accessibility and SEO I always try to add an alt tag to my images. You support (common) HTML attributes as part of the templates. Unfortunately the rendered output lacks a space in front of the alt tag making the rendered HTML invalid.

    <x-smart-image alt="My image" width="255" height="160" src="/images/myimage.jpg" data-src="my-image.jpg" />

    Expected:

    <img src='/smart/my-image.jpg' alt='My image' width='255' height='160' >

    Result:

    <img src='/smart/my-image.jpg'alt='My image' width='255' height='160' >

    Would be nice if you could fix this. Thank you!

    opened by podcasthosting 2
  • Tweaking performance

    Tweaking performance

    Discussed in https://github.com/dietercoopman/smart/discussions/3

    Originally posted by dietercoopman September 15, 2021 As stated on reddit by Jakeydev

    Serving the images as a base64 can be pretty bad at times though. First is performance - users will not be able cache these images as they are served inline in HTML. Secondly, image sizes are now increased by around 30% - thats just base64 bloat! Users on flakey connections now need to wait extra time to download the whole document before the browser can start rendering them!

    opened by dietercoopman 1
  • Prevent package to fetch image every single time

    Prevent package to fetch image every single time

    Discussed in https://github.com/dietercoopman/smart/discussions/2

    Originally posted by dietercoopman September 15, 2021 reaction on reddit by jakeydev :

    Finally, does your solution 'get' the image every single time it used? So to serve an image first the server downloads it, then the users browser has to base64 decode it to view it? Seems very inefficient!

    Would a better idea be downloading the private file locally - then doing your processing (resizing, reducing file size) - then serve the image file directly again? That way you get the added bonus of caching (both on the server and in browser!)?

    opened by dietercoopman 1
  • Lazy-loading

    Lazy-loading

    Hey, I think it is impossible to use lazy-loading with your package. Can I help you realize such functionality or maybe you already working on it?

    I use https://github.com/aFarkas/lazysizes library for lazy loading. It is a very simple and lightweight solution.

    opened by arm092 0
  • change cache mechanisme for data-src

    change cache mechanisme for data-src

    If you specify a data-src attribute now the code will pull the cached item from the cache and store it to a new cache variable , this is very slow. It would be better if it could be stored immediately with the correct name , so no renaming would be necessary.

    opened by dietercoopman 0
Releases(v1.6.5)
Owner
Dieter Coopman
👉 owner and 👨‍💻 mentor at Delta Solutions // Laravel evangelist // 🔥 creator of LLoadout
Dieter Coopman
Re-skinning BotCloaker enables you to add a SMART button at the end of all posts on your blog.

Re-skinning BotCloaker Wordpress Plugin Re-skinning BotCloaker enables you to add a SMART button at the end of all posts on your blog. Re-skinning Bot

Mohammed cha 120 Nov 11, 2022
Small Library to Serve Images in PHP in a Better Way (Resize, Compress) with Caching Support

A library for serving images and optimizing, changing their sizes, this library uses the caching feature, and in addition, it is very fast and small in size. In addition to these features, this library also optimizes images.

Developix 9 Oct 18, 2022
Object-Oriented API for PHP streams

Streamer Streamer is an Object-Oriented API for PHP streams. Why should I use Streams? A stream is a flow of bytes from one container to the other. Yo

Francois Zaninotto 270 Dec 21, 2022
PHP implementation for reading and writing Apache Parquet files/streams

php-parquet This is the first parquet file format reader/writer implementation in PHP, based on the Thrift sources provided by the Apache Foundation.

null 17 Oct 25, 2022
Test case to reproduce a PHP segmentation fault involving Xdebug, streams, and dates

The code in this repository causes a segmentation fault when run with PHP 8.0.6 on Fedora 33. This issue was originally reported to the Xdebug project

Matthew Turland 0 Jul 31, 2021
A smart way of seeding tables in Laravel

SmartSeeder for Laravel For Laravel 5, please use the 5.0 branch! For Laravel 4, please use the 4.2 branch! Seeding as it is currently done in Laravel

Jordan Lapp 190 Oct 6, 2022
Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)

COPS COPS stands for Calibre OPDS (and HTML) Php Server. See : COPS's home for more details. Don't forget to check the Wiki. Why ? In my opinion Calib

Sébastien Lucas 1.3k Jan 1, 2023
X1 - A very simple web based note solution that's designed to serve as my second brain.

X1 A very simple web based note solution that's designed to serve as my second brain. Starting Server To start the tool simply clone the repo and then

Joel Dare 118 Dec 28, 2022
Smart File System - Use SmartFileInfo with useful methods that you need everyday

Smart File System - Use SmartFileInfo with useful methods that you need everyday

null 78 Dec 22, 2022
The package provides the ability to write logs into the database synchronously or asynchronously, along with other logging channels.

Laravel database log channel The package provides the ability to write logs into the database synchronously or asynchronously, along with other loggin

Jarosław Goszowski 18 Nov 28, 2022
Provides the ability to notify developers of error logs via email or SMS.

?? Dev Notify Plugin ?? Requires OctoberCMS 2.0 ✨ What does this plugin do? Provides the ability to notify developers of error logs via email or SMS.

Albright Labs 1 Mar 28, 2022
Moodle ReactJS - gives you ability to use ReactJS inside any moodle page.

moodle-local_reactjs Moodle ReactJS - gives you ability to use ReactJS inside any moodle page. Note for devs: You'll need to set up npm dependencies d

SmartApp 5 Dec 14, 2022
Track your farming and pool performance on the Binance Smart Chain

farm.army - Frontend Track your farming and pool performance on the Binance Smart Chain. Tech Stack PHP 8 + Symfony node.js + npm (Webpack, Symfony en

farm.army 28 Sep 3, 2022
A proof-of-concept parser for the SMART Health Cards format.

SMART Health Cards parser A proof-of-concept parser for the SMART Health Cards format. This is not intended for production use. I just hacked this tog

Mikkel Paulson 55 Jul 31, 2022
Open Source Smart Meter with focus on privacy - you remain the master of your data.

volkszaehler.org volkszaehler.org is a free smart meter implementation with focus on data privacy. Demo demo.volkszaehler.org Quickstart The easiest w

volkszaehler.org project 176 Jan 4, 2023
Starless Sky is a network protocol for secure identities, providing the use of assymetric identities, public information, end-to-end messaging and smart contracts

Descentralized network protocol providing smart identity over an secure layer. What is the Starless Sky Protocol? Starless Sky is a network protocol f

Starless Sky Protocol 3 Jun 19, 2022
This project is based on the problem statement provided by the Minstry of HRD (India) for Smart India Hackathon '17.

This project is based on the problem statement provided by the Minstry of HRD (India) for Smart India Hackathon '17. As per the given problem statement, we need to solve the problem of bunching of marks at certain level, and problem of high scorers being at disadvantageous position due to lower competitive percentile.

Saransh Dave 4 Oct 13, 2022
Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3+ that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI.

laravelpodcast | A Laravel podcast manager package - v0.0.8 Introduction Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3

Jeremy Kenedy 22 Nov 4, 2022
Magento 2 Module that adds Donation Product Type. Enables the customer to add a donation (product) of a preferred amount to the cart.

Magento 2 Module Experius DonationProduct (RC1.0) Demo website: https://donationproduct.experius.nl Magento Marketplace: https://marketplace.magento.c

Experius 23 Apr 1, 2022