2017 © Pedro Peláez
 

symfony-bundle picture-bundle

Symfony bundle

image

tomatom/picture-bundle

Symfony bundle

  • Thursday, November 2, 2017
  • by b3da
  • Repository
  • 2 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

TomAtom/PictureBundle

picture, (*1)

Symfony Bundle for easy <picture>s :)

define breakpoints and use your assets as picture sources, without annoying image conversions and long code blocks, (*2)

Dependencies:

  • vipsthumbnail from libvips, (*3)

  • symfony/framework-standard-edition ">=2.8|~3.3", (*4)

Installation:

  • you need vipsthumbnail !, (install by sudo apt install libvips-tools, or you can compile your own or download here), (*5)

  • create project with Symfony framework, (*6)

  • composer require tomatom/picture-bundle "1.4", (*7)

  • add bundle to AppKernel.php:, (*8)

new TomAtom\PictureBundle\TomAtomPictureBundle(),
  • update db schema, install assets and clear cache ... and it's done!, (*9)

  • optionally add parameters to __parameters.yml(.dist)__ (define your own breakpoints etc.):, (*10)

# these are defaults
parameters:
    tt_picture_breakpoints: [575, 768, 991, 1199, 1690, 1920]
    tt_picture_converted_dir: '%kernel.project_dir%/web/tt_picture'
    tt_picture_jpeg_quality: 65

Usage:

  • in template, call (jpg, png and gif are supported):
{# as function #}
{{ picture(asset('path/to/asset.jpg')) }}

{# as filter #}
{{ asset('path/to/asset.jpg') | picture }}

<picture> is generated and image is converted on first render, (*11)

  • you can define custom breakpoints and/or jpeg quality for each image, when needed:
{# as function with custom breakpoints defined per image #}
{{ picture(asset('path/to/asset.jpg'), [300, 600, 1200]) }}

{# as function with custom jpeg quality defined per image #}
{{ picture(asset('path/to/asset.jpg'), null, 99) }}


{# as filter with custom breakpoints defined per image #}
{{ asset('path/to/asset.jpg') | picture([300, 600, 1200]) }}

{# as filter with custom jpeg quality defined per image #}
{{ asset('path/to/asset.jpg') | picture(null, 99) }}


{# use with SonataMedia images #}
{{ mediaUrl(entity.media, 'reference') | picture }}
  • you can retrieve converted images in PHP code too (in case you need to serve images from API, etc.), like this:
// asset url - same as in Twig template
$originalAssetUrl = $this->container->get('assets.packages')->getUrl('bundles/app/images/test.jpg');
// get PictureHelper from container
$pictureHelper = $this->container->get('tomatom_picture.util.picture_helper');

// get array of all converted images for asset
$allConveretedImages = $pictureHelper->getAllConverted($originalAssetUrl);

// or specific image for breakpoint
$convertedAssetUrl = $pictureHelper->getAssetUrl($originalAssetUrl, 1920);
$convertedFilePath = $pictureHelper->getFilePath($originalAssetUrl, 1920);

// convert images if not exists and get array of converted images (for global breakpoints)
$allConveretedImages = $pictureHelper->convert($originalAssetUrl);
// convert images if not exists and get array of converted images (custom breakpoints and jpeg quality)
$allConveretedImages = $pictureHelper->convert($originalAssetUrl, [300, 600, 900], 70);

Todo:

  • [x] jpeg quality as param
  • [x] jpeg quality as param in template
  • [x] breakpoints as param in template
  • [ ] cmd for batch converting
  • [x] converting of images other than assets (like from 'web/uploads', etc)
  • [x] helper for retrieving converted images in controller / cmd / service..
  • [x] helper for SonataMedia image path

The Versions

02/11 2017

dev-master

9999999-dev

Symfony bundle

  Sources   Download

GPLv2

The Requires

 

by Tom Atom

image bundle symfony picture picture bundle symfony image symfony srcset srcset bundle

02/11 2017

1.4

1.4.0.0

Symfony bundle

  Sources   Download

GPLv2

The Requires

 

by Tom Atom

image bundle symfony picture picture bundle symfony image symfony srcset srcset bundle

27/10 2017

1.3

1.3.0.0

Symfony bundle

  Sources   Download

GPLv2

The Requires

 

by Tom Atom

image bundle symfony picture picture bundle symfony image symfony srcset srcset bundle

26/10 2017

1.2

1.2.0.0

Symfony bundle

  Sources   Download

GPLv2

The Requires

 

by Tom Atom

image bundle symfony picture picture bundle symfony image symfony srcset srcset bundle

25/10 2017

1.1

1.1.0.0

Symfony bundle

  Sources   Download

GPLv2

The Requires

 

by Tom Atom

image bundle symfony picture picture bundle symfony image symfony srcset srcset bundle

25/10 2017

1.0

1.0.0.0

Symfony bundle

  Sources   Download

GPLv2

The Requires

 

by Tom Atom

image bundle symfony picture picture bundle symfony image symfony srcset srcset bundle