All Projects → pratiksh404 → laravel-thumbnails

pratiksh404 / laravel-thumbnails

Licence: MIT license
Laravel Package for making thumbnails instantly

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-thumbnails

Algoflow
Algorithm Visualizer
Stars: ✭ 21 (-58.82%)
Mutual labels:  hacktoberfest2020
hello-world-all-programming-language
This is a repository of examples of hello world programs in all programming languages
Stars: ✭ 23 (-54.9%)
Mutual labels:  hacktoberfest2020
DockerENT
The only open-source tool to analyze vulnerabilities and configuration issues with running docker container(s) and docker networks.
Stars: ✭ 124 (+143.14%)
Mutual labels:  hacktoberfest2020
styles
A collection of cool effects in html, css and javascript.
Stars: ✭ 35 (-31.37%)
Mutual labels:  hacktoberfest2020
HacktoberFest2021
hacktoberfest-accepted repository
Stars: ✭ 25 (-50.98%)
Mutual labels:  hacktoberfest2020
Geektoberfest-Main
This is the starting point of Geektoberfest! Have a look at the readme for Rules and Guidelines, you can also contribute to the collaborative website in this repo!
Stars: ✭ 12 (-76.47%)
Mutual labels:  hacktoberfest2020
MementoEmbed
A service that provides archive-aware oEmbed-compatible embeddable surrogates (social cards, thumbnails, etc.) for archived web pages (mementos).
Stars: ✭ 13 (-74.51%)
Mutual labels:  thumbnails
lamba-thumbnailer
AWS S3 Video Thumbnailer with Lambda
Stars: ✭ 21 (-58.82%)
Mutual labels:  thumbnails
imtool
🖼️ Client-side canvas-based image manipulation library.
Stars: ✭ 38 (-25.49%)
Mutual labels:  thumbnails
ui-design-daily
abdulqudus001.github.io/ui-design-daily/
Stars: ✭ 21 (-58.82%)
Mutual labels:  hacktoberfest2020
Footnote
Simple SwiftUI + CoreData app
Stars: ✭ 38 (-25.49%)
Mutual labels:  hacktoberfest2020
Hacktoberfest-2020-Baby
No description or website provided.
Stars: ✭ 31 (-39.22%)
Mutual labels:  hacktoberfest2020
o-fish-ios
iOS app for the Officer's Fishery Information Sharing Hub (O-FISH). The mobile app allows fisheries officers to document and share critical information gathered during a routine vessel inspection.
Stars: ✭ 28 (-45.1%)
Mutual labels:  hacktoberfest2020
Hacktoberfest-Algorithms
This repository is mainly open to those who are looking to make some PRs for the Hacktoberfest 2020 event. In this repository, you can add programs on some useful algorithms for Competitive Programming in any languages.
Stars: ✭ 47 (-7.84%)
Mutual labels:  hacktoberfest2020
ray-tracer
My ongoing effort to learn how to make Ray Tracers
Stars: ✭ 14 (-72.55%)
Mutual labels:  hacktoberfest2020
godot tools
A set of GDScript EditorScript and EditorPlugins tools that automate boring tasks on Godot Engine.
Stars: ✭ 50 (-1.96%)
Mutual labels:  hacktoberfest2020
Web-App
A Web Application foundation for Raku
Stars: ✭ 21 (-58.82%)
Mutual labels:  hacktoberfest2020
nano photos provider2
PHP photos provider for nanogallery2
Stars: ✭ 37 (-27.45%)
Mutual labels:  thumbnails
Plasma-Donor-App
An open-source app that helps in connecting patients and plasma donors. This is a beginner-friendly repository that helps you learn the basics of android development, git, and GitHub. Happy Hacktober!
Stars: ✭ 58 (+13.73%)
Mutual labels:  hacktoberfest2020
Logan1x.github.io
Personal Portfolio Website 🌐
Stars: ✭ 122 (+139.22%)
Mutual labels:  hacktoberfest2020

Laravel Thumbnails

Stars Downloads StyleCI Build Status Scrutinizer Code Quality CodeFactor License Laravel News MadeWithLaravel.com shield

Laravel Thumbnail Generator

Package for uploading the image and saving that image along with it's thumbnail.

What does it do ?

  • Uploads Image
  • Make its thumbnail i.e low quality, resized version of its parent image

Why use thumbnails ?

The small file size of thumbnails makes it possible for website designers to offer visitors a lot of content immediately without increasing the loading time of the page. Also why use full glory of that image if you just have to crunched it up to tiny space... Use thumbnail.

Installation

Run Composer Require Command

$ composer require drh2so4/thumbnail

Use thumbnail trait to your model

<?php

namespace App;

use drh2so4\Thumbnail\Traits\thumbnail;
use Illuminate\Database\Eloquent\Model;

class Image extends Model
{
    use Thumbnail;

    protected $fillable = ['image'];
}

This model consists of following methods :-

  • makeThumbnail
  • thumbnail
  • uploadImage
  • hasThumbnail
  • thumbnailCount
  • imageDetail
  • hardDelete

Usages

Package utilizes it's trait method, let us guide you to use that

makeThumbnail

This method is responsible for actually uploading the image and making its thumbnail.

    public function store(Request $request)
    {
        $image = Image::create($this->validateData());
        $image->makeThumbnail('image'); //This handles uploading image and storing it's thumbnail
        return redirect('/imageUpload');
    }

Same can go with update method.

thumbnail

Well, we created our thumbnail but how to use it, let me guide through that When we uploaded image with name suppose "batman". Image is upload with name batman-current_time_instant i.e (batman-1521549.jpg).

What about thumbnail... well thumbnail uses it's parent image name followed by -size i.e batman-1521549-medium-jpg, batman-1521549-small.jpg

How to make thumbnail ?

There are the options you can have for making thumbnails :-

  • Default Option
  • Universal Custom Thumbnails
  • Specfic Custom Thumbnails

Default Option

you can just call the following and the packages will handle the rest

    $image->makeThumbnail('image'); //Here the first parameter is image attribute name saved in db

Note : if the attribute dedicated for storing image is named 'image' you don't have to pass image attribute name jusr use $image->makeThumbnail();

Universal Custom Thumbnails

here you should mention the thumbnails that you want to be applied on every case. when you publish thumbnail.php config file you will find 'thumbnails' property where you can mention your custom thumbnails

    /*
    |--------------------------------------------------------------------------
    | Custom Thumbnail Creation
    |--------------------------------------------------------------------------
    | Uncomment to create...
    */

    /*     "thumbnails" => [
        [
            "thumbnail-name" => "medium",
            "thumbnail-width" => 800,
            "thumbnail-height" => 600,
            "thumbnail-quality" => 60
        ],
        [
            "thumbnail-name" => "small",
            "thumbnail-width" => 400,
            "thumbnail-height" => 300,
            "thumbnail-quality" => 30
        ]
    ] */

Note: This will override default option

Specfic Custom Thumbnails

Suppose you have applied Universal Custom Thumbnails but need to have changes for specific image field then you can pass array of custom requirements :

        $thumbnails = [
            'storage' => 'customs/embed',
            'width' => '600',
            'height' => '400',
            'quality' => '70',
            'thumbnails' => [
                [
                    'thumbnail-name' => 'customSmall',
                    'thumbnail-width' => '300',
                    'thumbnail-height' => '200',
                    'thumbnail-quality' => '50'
                ]
            ]
        ];
        $image->makeThumbnail('image', $thumbnails);

How about multiple image uploads

If you are performing multiple image upload at once pass image key to thumbnail array. here $img is one of the image in chunk of images passed

// Controller Store Method
public function store(Request $request)
{
    $image = Image::create(['images'=>$request->images]);
    foreach($request->images as $img)
    {
        $this->multipleImageUpload($image,$img);
    }
}
// Multiple Image Upload
    private function multipleImageUpload($image, $img)
    {
        $multiple = [
            'storage' => 'custom_test/folder/another_folder/image',
            'width' => '600',
            'height' => '400',
            'quality' => '70',
            'image' => $img,
            'thumbnails' => [
                [
                    'thumbnail-name' => 'small',
                    'thumbnail-width' => '300',
                    'thumbnail-height' => '200',
                    'thumbnail-quality' => '50'
                ]
            ]
        ];
        $image->makeThumbnail('image', $multiple);
    }

How to use thumbnail ?

Just call as following

// Here the first parameter 'image' is the name of sttribute that is saved in db for image

    @foreach ($images as $image)
        <img src="{{asset($image->thumbnail('image','small'))}}"> // For small thumbnail
    <img src="{{asset($image->thumbnail('image','medium'))}}"> // For medium thumbnail
    @endforeach

if you are using custom thumbnail configured from config file just call as follows

// Here the first parameter 'image' is the name of sttribute that is saved in db for image
// Second parameter is the name of thumbnail that you gave in 'thumbnail-name' in the config file on custom thumbnail field called 'thumbnails'
    @foreach ($images as $image)
        <img src="{{asset($image->thumbnail('image','small'))}}"> // For small thumbnail
    <img src="{{asset($image->thumbnail('image','medium'))}}"> // For medium thumbnail
    @endforeach

Notice that parameter of function thumbnail is string same as value given for "thumbnail-name" in config file.

Thumbnail's image property is predefined but if you wish to change that publish it's config file thumbnail.php

php artisan vendor:publish --tag=thumbnail-config

Image Property

You can obtaing the detail image property by using method imageDetail($image,$size)

// imageDetail method takes two parameter
// Model image attribute name (Mandatory)
// If you want thumbnail property pass its size (optional)

$image->imageDetail('image'); // Parent Image Detail Property
$image->imageDetail('image','small') // Small thumbnail related to parent image

What Image Property/Detail Gives

Default Thumbnail Image Properties

Property Return Type Description Example
image string Image path stored in DB $image->imageDetail('image')->image
name string Image Stored Name (without extension) $image->imageDetail('image')->name
fullname string Image Stored Name (with extension) $image->imageDetail('image')->fullname
extension string Image Extension Name $image->imageDetail('image')->extension
path string Image Storage Path $image->imageDetail('image')->path
directory string Image Stored Directory $image->imageDetail('image')->directory
location string Image Full Location Path $image->imageDetail('image')->location
property array Image Property array $image->imageDetail('image')->property

Image Property array ($image->imageDetail('image')->property)

Property Return Type Description Example
real_name string Image Real Name (without timestamp and size label) $image->imageDetail('image')->property->name
size integer Image Storage Size $image->imageDetail('image')->property->fullname
directory string Image Stored Directory $image->imageDetail('image')->property->directory
location string Image Full Location Path $image->imageDetail('image')->property->location
has_thumbnail boolean Image's Thumbnail Check $image->imageDetail('image')->property->has_thumbnail
thumbnail_count integer Image Thumbnail Count $image->imageDetail('image')->property->thumbnail_count
thumbnails array Return all thumbnail Detail $image->imageDetail('image')->property->thumbnails

Image Thumbnail Property

Property Return Type Description
image string Thumbnail Name
real_name string Thumbnail Real Name (without timestamp and size label)
size integer Thumbnail Storage Size
created_date Carbon Thumbnail Created Date
path string Thumbnail Storage Path
directory string Thumbnail Stored Directory
location string Thumbnail Full Location Path

Check if image has thumbnail

$image->hasThumbnail('image'); // Check for any availabe thumbnail
$image->hasThumbnail('image','small'); // Second paremater is thumbnail size check

Obtain Image Thumbnail Count

$image->thumbnailCount('image');

Hard Delete Image with Thumbnails

$image->hardDelete('image'); // First parameter is db attribute name for image

Hard Delete Image with Thumbnails adn its parent

$image->hardDeleteWithParent('image'); // First parameter is db attribute name for image

Upload Only Umage

$solo_image = [
                'storage' => 'solo',
                'width' => '600',
                'height' => '300',
                'quality' => '70',
            ];
            $image->uploadImage('image', $solo_image); // Second Parameter is not necessary if default settings is to be applied
            // OR
            $image->uploadImage('image'); // Image Upload with default setting

Our config file looks like follows :-

<?php

return [


    /*
    |--------------------------------------------------------------------------
    |  Thumbnail Feature
    |--------------------------------------------------------------------------
    |
    | This option defines whether to use Package's Thumbnail feature or not
    | Default option is true
    |
    */
    'thumbnail' => true,

    /*
    |--------------------------------------------------------------------------
    | Thumbnail Qualities
    |--------------------------------------------------------------------------
    |
    | These options are default post image and its thumbnail quality
    |
    |
    */

    'image_quality' => 80,
    'medium_thumbnail_quality' => 60,
    'small_thumbnail_quality' => 30,

    /*
    |--------------------------------------------------------------------------
    | Default Image Fit Size
    |--------------------------------------------------------------------------
    |
    | These options is default post imahe height and width fit size
    |
    |
    */

    'img_width' => 1000,
    'img_height' => 800,

    'medium_thumbnail_width' => 800,
    'medium_thumbnail_height' => 600,

    'small_thumbnail_width' => 400,
    'small_thumbnail_height' => 300,

    /*
    |--------------------------------------------------------------------------
    | Image and Thumbnail Storage Path
    |--------------------------------------------------------------------------
    |
    | Define your default image storage location along with its thumbnail
    |
    |
    */

    "storage_path" => "uploads",

    /*
    |--------------------------------------------------------------------------
    | Custom Thumbnail Creation
    |--------------------------------------------------------------------------
    | Uncomment to create...
    */

    /*     "thumbnails" => [
        [
            "thumbnail-name" => "medium",
            "thumbnail-width" => 800,
            "thumbnail-height" => 600,
            "thumbnail-quality" => 60
        ],
        [
            "thumbnail-name" => "small",
            "thumbnail-width" => 400,
            "thumbnail-height" => 300,
            "thumbnail-quality" => 30
        ],
        ] */
];

Feel free to change the values

Default Thumbnail Image Properties

Thumbnail Width Height Quality
Uploaded Image 1000 800 80
Medium Thumbnail 800 600 60
Small Thumbnail 400 300 30

Laravel Thumbnails

Todos

  • Error Handling
  • Image Caching
  • Maintainabilty

Package Used

License

MIT

DOCTYPE NEPAL || DR.H2SO4

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].