thelia/image-factory-module

Installs: 299

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 6

Forks: 4

Open Issues: 0

Type:thelia-module

0.4.3 2016-09-29 12:33 UTC

This package is auto-updated.

Last update: 2024-10-14 22:19:53 UTC


README

This module provides an alternative to managing images in Thelia.

Installation

Manually

  • Copy the module into <thelia_root>/local/modules/ directory and be sure that the name of the module is ImageFactory.
  • Activate it in your thelia administration panel

Composer

Add it in your main thelia composer.json file

composer require thelia/image-factory-module:~0.4.0

Usage

With Smarty

{* With product id *}
<ul>
  {image_factory attr=['class'=> 'example-1'] code='test' view="product" view_id="325" inner="<li>?</li>" limit=10}
</ul>

{* With product sale element id *}
<ul>
  {image_factory attr=['class'=> 'example-1'] code='test' view="product_sale_element" view_id="21" inner="<li>?</li>" limit=10}
</ul>

{* With image id *}
<ul>
  {image_factory attr=['class'=> 'example-2'] code='test' view="product" image_id="10,11,12,13,14" inner="<li>?</li>"}
</ul>

{* With image file name *}
<ul>
  {image_factory attr=['class'=> 'example-3'] code='test' file_name="sample-image-394.png,sample-image-396.png" inner="<li>?</li>"}
</ul>

{* With force image not found *}
<ul>
  {image_factory force_not_found=true code='test' file_name="an-image-which-does-not-exist"}
</ul>


{* With an variable *}

{image_factory out="images" force_not_found=true code='test' file_name="an-image-which-does-not-exist"}

{$images|var_dump} {* $images is an collection of type ImageFactory\Response\FactoryResponseCollection *}
{$images[0]|var_dump} {* $images[0] is an object of type ImageFactory\Response\FactoryResponse *}

{* It's possibale to iterate on the collection *}

{foreach from=$images key=k item=image}
 {$image|var_dump}
{/foreach}

{* The object FactoryEntity implements the method __toString. This method returns the html code. *}

{foreach from=$images key=k item=image}
 {$image} {* Display the html code *}
{/foreach}

With PHP

    /** @var \ImageFactory\Handler\FactoryHandler $factoryHandler */
    $factoryHandler = $this->getContainer()->get('image_factory.factory_handler');

    $image = ProductImageQuery::create()->findOne();
    $factoryCode = 'test';

    $url = $factoryHandler->getUrl($factoryCode, null, 'path/your/image');
    $url = $factoryHandler->getUrl($factoryCode, $image);

    $uri = $factoryHandler->getUri($factoryCode, null, 'path/your/image');
    $uri = $factoryHandler->getUri($factoryCode, $image);

Commands

The command image-factory:generate-destination

For generate all images of a specific factory

    php Thelia image-factory:generate-destination product-high,product-medium,product-small

Or for all factories

    php Thelia image-factory:generate-destination "*"

With this command, the images already present on the destination paths will not be regenerated. It's possible to force the generation process by adding the option --force.

    php Thelia image-factory:generate-destination product-high,product-medium,product-small --force

The command image-factory:reload-factory

For reload all factories in the cache

    php Thelia image-factory:reload-factory

Configure your factories on your database (table image_factory)

Todo

  • The configuration interface on the back office