Git Product home page Git Product logo

thumbs's Introduction

Bolt Thumbs

Image Thumbnail handler for Bolt

Installation

Bolt Thumbs is installed as a default dependency of Bolt. However, for use independently it can be included in your Composer project:

composer require bolt/thumbs:^3.4

Should you want to work with the development branch(es), you can specficy those as Composer requirements instead.

To install the 3.x development branch:

composer require bolt/thumbs:dev-3.x@dev

Alternatively to install the master branch (which requires Silex 2):

composer require bolt/thumbs:dev-master@dev

Configuration

If you've already got a working installation of Bolt, you can safely skip this.

To use the Botl Thumbs service provider onto your Silex based application, simply ->register() the \Bolt\Provider\ThumbnailsServiceProvider class in your registration phase, e.g.:

    /** @var \Silex\Application $app */
    $app->register(new \Bolt\Provider\ThumbnailsServiceProvider())

thumbs's People

Contributors

bobdenotter avatar carsonf avatar dadaxr avatar gdmac avatar gwendolenlynch avatar jarjak avatar ntomka avatar pinpickle avatar rarila avatar rixbeck avatar rossriley avatar sahassar avatar tobe998 avatar yceforp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thumbs's Issues

bolt thumbnail setting to save files (static) is ignored

the bolt config thumbnails setting to save or not to save files is ignored
fresh 3.x install (master) create first user, have a thumbs directory,
then open site, see thumbs/1920x1080c image1.jpg is created,
even though config.yml thumbnails: save_files: false

in Bolt 3.master there is one find to the config setting and it is never referred to
https://github.com/bolt/bolt/blob/master/src/Provider/ThumbnailsServiceProvider.php#L60

The thumbs package seems to always generate the staticFile regardless
https://github.com/bolt/bolt-thumbs/blob/master/src/Responder.php#L73

A possible solution could be to unset/unmount/return null the web filesystem
if the "save_files" setting is set to false when initializing the provider here:
https://github.com/bolt/bolt/blob/master/src/Provider/ThumbnailsServiceProvider.php#L33

Thumbnails Error when running inside Docker container

Bolt Thumbs Error

I have the same problem explained here bolt/bolt#5329, Bolt running inside Docker (Apache/PHP 5.6) doesn't generate the thumbnails.

I traced the error to here https://github.com/bolt/bolt-thumbs/blob/master/src/Creator.php#L36, it is returning false when Bolt runs inside Docker with all the required (and enabled) extensions.

Stack trace

# 1 Symfony\Component\Debug\ErrorHandler::handleError(4096, "Method Bolt\Thumbs\Thumbnail:…",  "/var/www/html/vendor/symfony/ …", 402, [array]) 
[root]/vendor/symfony/http-foundation/Response.php # line 402
# 2 Symfony\Component\HttpFoundation\Response::setContent(Thumbnail) 
[root]/vendor/bolt/thumbs/src/Response.php # line 81
# 3 Bolt\Thumbs\Response::setThumbnail(Thumbnail, [false], [true]) 
[root]/vendor/bolt/thumbs/src/Response.php # line 35
# 4 Bolt\Thumbs\Response::__construct(Thumbnail) 
[root]/vendor/bolt/thumbs/src/Controller.php # line 136
# 5 Bolt\Thumbs\Controller::serve(Application, Request, "agriculture-cereals-field-621 …", "crop", 54, 40) 
[root]/vendor/bolt/thumbs/src/Controller.php # line 81
# 6 Bolt\Thumbs\Controller::thumbnail(Application, Request, "agriculture-cereals-field-621 …", "crop", 54,  40) 
# 7 call_user_func_array([array], [array]) 
[root]/vendor/symfony/http-kernel/HttpKernel.php # line 144
# 8 Symfony\Component\HttpKernel\HttpKernel::handleRaw(Request, 1) 
[root]/vendor/symfony/http-kernel/HttpKernel.php # line 64
# 9 Symfony\Component\HttpKernel\HttpKernel::handle(Request, 1, [true]) 
[root]/vendor/silex/silex/src/Silex/Application.php # line 586
# 10    Silex\Application::handle(Request) 
[root]/vendor/silex/silex/src/Silex/Application.php # line 563
# 11    Silex\Application::run([NULL]) 
[root]/vendor/bolt/bolt/src/Application.php # line 93
# 12    Bolt\Application::run() 
[root]/index.php # line 14

[RFC] Allow Quality and Crop Direction to be configurable

Thumbnail quality is currently a "global" value. Whatever is set in config.yml is the thumb quality for every thumb generated by bolt. In many instances this is less than ideal when small thumbnails could be created with a lesser quality.

The crop direction is always 0. You cannot crop in different directions - say from the left or right. There is code for a Point (https://github.com/bolt/bolt-thumbs/blob/master/src/Creator.php#L127-L187) but you can't set any points as an end user.

A Possible addition to thumbs would be to pass in an array with the parameters you want to over ride.

<img src="{{ record.image|thumbnail(100, 100, "c", { crop: [ x-direction, y-direction ],  quality: 60, } ) }} >  

the issue with a crop direction is determining the "focus" or where you want to crop from and getting those dimensions. The "editor" won't necessarily know how to do this but a designer might and a developer could figure out

Examples:
Responsive Images using srcset and lazy-loading the default image src. A low quality placeholder could be generated instead of a "full quality" (80) image. Here is a js library and examples showing a low quality placeholder and lazyload https://github.com/aFarkas/lazysizes#lqipblurry-image-placeholderblur-up-image-technique

<img class="lazyload"  
  sizes="100vw"  
  srcset="thumb-1.jpg 1x, thumb-2.jpg 2x, thumb-3.jpg 3x"  
  src="low-quality-thumb.jpg"  >  <!-- thumb is quality less than 80 --> 

Or using Client Hints and serving a low quality image Example Here using service worker

Art Directed Images (picture element)

<picture>
  <source media="(min-width: 50em)"
    srcset="regular-full-width-thumbnail.jpg">
  <source srcset="small-image-cropped.jpg">
  <img src="medium-sized-thumbnail.jpg" alt="">
</picture>  

Having either of these will go a long way to fully supporting these HTML5 standards. Particularly the picture element since you have to use a bunch of your own custom code currently to use the picture element with bolt thumbs or completely replace bolt's thumbnail package

Mount point in path

We need to be able to include mount point in path. Currently we are guessing by checking each filesystem to see if the file exists 👎 . It needs to be optional for BC, which puts us in a tight spot.

Ideally would do this: /thumbs/5x5c/theme/foo/bar.jpg
But when it is not included, /thumbs/5x5c/foo/bar.jpg: mount point would be foo and path would be bar.jpg.

We could do one of these:

/thumbs/theme/5x5c/foo/bar.jpg <= works because 5x5c separates the regex
/thumbs/5x5c/foo/bar.jpg?mountPoint=theme <= Bleh :(

We could also do another controller prefix. That would create a bit more work, but it's doable.

/thumb/5x5c/theme/foo/bar.jpg
/thumbnail/5x5c/theme/foo/bar.jpg

Any other thoughts?

Preserve gif animation when creating thumbs

*Moving this over from the Bolt tracker #1381 *

By @davidgenetic

Just ran into this issue.
Solved it (the hacky way) by using http://www.gdenhancer.com/ [EDIT: Now leads to a spam site]

in /vendor/bolt/thumbs/src/ThumbnailCreator.php line 170 :

require_once(__DIR__ . '/../../../../app/classes/gdenhancer/GDEnhancer.php');

// Preserve animation in GIF.
// I only use 'crop'...
if ($type == 'gif' && $crop) {
  $img = new \gdenhancer\GDEnhancer($src);

  // Needs more memory.
  $memlim = ini_get('memory_limit');
  ini_set('memory_limit', '256M');

  $img->backgroundResize($width, $height, 'fill');
  $save = $img->save();

  // Reset memory limit.
  ini_set('memory_limit', $memlim);

  header('content-type:' . $save['mime']);
  return $save['contents'];
}

urldecode

I think this line needs an urldecode call in cases, when url contains special url encoded strings (eg. %20):

$path = urldecode($this->request->getPathInfo());

cc. @rossriley

Tests on `master` are broken.

Quoting @GawainLynch from #41:

Yeah, the test failure exists in master too … I've spent a bit of time on it, and it looks to be coming from filesystem changes (test failure), my concern was that it was a sign of a bigger problem and have been trying to find time with @CarsonF to check both.

Custom thumbnail paths

Is there a way to add custom paths for thumbnailing (eg. for extensions)? Currently thumbnails can be generated only from files and theme paths.

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.