Giter VIP home page Giter VIP logo

statamic-splash's Introduction

Splash

Browse Unsplash images right from the CP.

Installation

Install the addon via composer:

composer require aryehraber/statamic-splash

Publish the fieldtype assets & config file:

php please vendor:publish --tag=splash-config

Once installed, you will need to add an Unsplash API Access Key to config/splash.php.

You can register for a free account via the Unsplash Developers page. Next, simply create a "New Application" and use the Demo Access Key, which allows 50 requests/hour, or go through the approval process to increase to 5000 requests/hour (this is still free but takes a little more effort). Note: "requests" only refers to search queries in the CP, once an image has been selected you will be referencing the CDN link which doesn't go through the API.

Usage

Simply add a field inside your blueprint and use type: splash to get started.

Blueprint

fields:
  -
    handle: hero_image
    field:
      type: splash

After selecting an image and saving your content, the Unsplash response data will be accessible in templates using Antlers (more on saved photo data below). The image itself will not be saved inside your Asset Container, instead you will be referencing images using Unsplash's CDN, also called Hotlinking (this is required by their API Guidelines).

The benefit here is that it takes a significant load off your server, since images are often the heaviest assets on a page. Additionally, since Unsplash's CDN is spread worldwide, images will load super fast regardless of the visitor's location.

Tags

Raw

{{ splash:raw :image="field_name" }}

This tag outputs the CDN link to the image's raw URL. Due to the high-quality nature of Unsplash photos, images are often 10-20MB, which is overkill for most websites; you can therefore use a few Glide-like parameters to request exactly what you need (more info below).

Example

{{ splash:raw :image="hero_image" width="2000" quality="80" }}

Image

{{ splash:image :image="field_name" }} or {{ splash:field_name }}

This tag also outputs the CDN link to the image's raw URL, but includes a few sensible defaults to reduce the image filesize a whole lot.

Any of these params can be overriden by using the parameters listed below, the defaults used are:

'q' => '80',
'w' => '1500',
'fit' => 'crop',
'crop' => 'faces,edges',
'auto' => 'format',

Example

{{ splash:image :image="hero_image" width="1000" }}

Or using the shorthand:

{{ splash:hero_image width="1000" }}

Attribution

{{ splash:attribution :image="field_name" }}

This tag outputs the Unsplash attribution text from their API Guidelines, including links to the photographer's profile and Unsplash website.

Example

{{ splash:attribution :image="hero_image" }}

Output

Photo by <a href="https://unsplash.com/@anniespratt?utm_source=statamic_splash&utm_medium=referral">Annie Spratt</a> on <a href="https://unsplash.com/?utm_source=statamic_splash&utm_medium=referral">Unsplash</a>

Since the photo's meta data is stored inside your content, you can also loop over the photographer's data using Antlers:

{{ hero_image:user }}
  <!-- access available user data -->
{{ /hero_image:user }}

Photo Data

By default, only the required photo data is saved from the Unsplash response data for this addon to work. You may specify additional keys using dot notation in the data_saved config option inside config/splash.php.

Example

<?php

return [
    'data_saved' => [
        'description',
        'links',
        'user.username',
        'user.bio',
    ],
    // ...
];

Alternatively, if you would like to save ALL photo data, you may use the all option instead.

<?php

return [
    'data_saved' => 'all',
    // ...
];

Parameters

Splash offers a number of Glide-like parameters to transform images to your needs. You can pass any Unsplash parameter into the raw and image tags to get started. Just like when using Glide within Statamic, you can also use the easier-to-read alias parameters below:

Param Description
width Sets the width (in pixels).
height Sets the height (in pixels).
square Shortcut to set width and height to the same value.
quality Sets the compression quality (value between 0 and 100).
format Encodes the image to a specific format (recommended to use auto="format" instead to auto-pick based on visitor's browser).
dpr Adjusts the device pixel ratio of the image.
fit Changes the fit of the image within the specified dimensions (see all available values on Imgix).
crop Applies cropping to the image (see all available values on Imgix).
auto Automates a baseline level of optimization for the image (see all available values on Imgix).

statamic-splash's People

Contributors

aryehraber avatar pryley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

statamic-splash's Issues

Statamic v4 Support

I'm unable to upgrade to v4 because of the requirement in the composer.json file. A new release is needed.

UI Issues

The UI for the search / image picker is a little broken (tested in both Chrome and Firefox):

image

I can't seem to be able to select an image either, the cursor is a zoom icon?

Doesn't seem to be any console errors, so I can't help much more.

Using Statamic v3 Beta 28

Addon not loading when deployed to server

When deploying to my server using the below Forge deploy script, the addon tags or fieldtype are not found. I suspect this might be a case sensitivity issue, as the addon works perfectly fine locally.

Here's my deploy script and error below:

cd /home/forge/thedepressionproject.mike-martin.ca
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader

https://flareapp.io/share/x7K3107R

Download not triggered

The plugin does not seem to properly implement the Unsplash API Guidelines with regard to triggering downloads. When selecting an image, the plugin should send a request to the download endpoint.

Since no downloads are registered with the Unsplash API we are stuck in Demo mode (max 50 requests/h) and are unable to upgrade to Production mode (max 5000 requests/h)

See point 2 in this general guide:
https://help.unsplash.com/en/articles/2511245-unsplash-api-guidelines

And this page specifically discussing the download endpoint:
https://help.unsplash.com/en/articles/2511258-guideline-triggering-a-download

When your application performs something similar to a download (like when a user chooses the image to include in a blog post, set as a header, etc.), you must send a request to the download endpoint returned under the photo.links.download_location property.

Problem selecting IMG

Not sure if I am doing something wrong, but when I am trying to select an image it opens up larger in the background and the previously greyed out select button is hidden. Clicking again gets rid of the image in the background and the buttons return, but the image is unselected, so I cannot click select... with resizing the image the select button comes into view sometimes and I can actually select. Any tips about this, is it a bug? No JS error is triggered. See screenshot below.
Screenshot 2020-12-07 at 15 03 59

The Image preview stopped working

This is what i see when i try to select an image to use
Screen Shot 2022-02-03 at 2 50 21 PM

I see the images request does come back successfully from unsplash API but the preview loading images stay as this forever

My environment:
PHP: 8.0
Laravel: 8.82.0
statamic : 3.2.32
statamic-splash: 1.0.6

Suggestion: Streamline data saved to entry

I just noticed the addon is saving approx 130 lines of data to the entry for a single image... do you think we could trim this down? a lot of that information isn't needed.

Perhaps a config file that stores an array of values to save, and the default can be the bare minimum to load an image.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.