Download the PHP package rokka/twig without Composer

On this page you can find all versions of the php package rokka/twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twig

rokka/twig

A twig extension to use rokka related methods in your twig templates.

This extension provides filters and functions to translate rokka hashes or image file references into rokka URLs. Some filters operate on rokka URLs to add stack options.

When working with file references, this extension can upload image files to rokka as necessary. Uploading on the fly introduces a considerable overhead. If you build a CMS, we recommend to upload images to rokka on creation or in a background process, and use the rokka image hash with the rokka_generate_url twig function in the template, to avoid the first rendering taking a performance hit. The main use case for uploading on the fly is static site generators where you pre-render the pages and then deploy the rendered code.

Installation

Note: If you use the Rokka Symfony Bundle, the twig extension is automatically installed and registered.

Add the following code to your Twig\Environment setup:

With these two steps, the rokka filters and functions become available.

Usage

You specify an image file that is available locally (or through a image locator, see below). The twig extension checks if it knows the rokka hash for that image, and if it does not, uploads the image to rokka and stores the hash. Then it generates the requested URL with the rokka hash.

Storing and reading hashes

By default, the plugin stores a json file next to each image file. If you want to overwrite this behaviour (for example to store hashes in a database), you need to extend the \Rokka\Client\TemplateHelper\AbstractCallbacks to implement the desired behaviour and provide an instance of that class to the RokkaExtension constructor.

Non standard image file locations

You can write your own class to load the source images, for example when they are not in the local file system. Implement the Rokka\Twig\Resolver\ResolverInterface to implement your image loading logic and provide an instance of that class to the RokkaExtension constructor.

Twig filters

The filters are applied to either the path to an image, an SplFileInfo object, a rokka hash or a Rokka\Client\LocalImage\AbstractLocalImage instance.

The filters need the stack that you want to use. Make sure that you defined the stack in rokka before using it.

You can force a format to have rokka convert your image to the desired format.

Most filters accept an seo string and the seo language. The language is used to transliterate the seo string into a URL safe string (e.g. for german, change ä to ae or for french change é to e).

rokka_stack_url: create an image URL for rokka with the desired stack

rokka_stack_url(stack, format = "jpg", seo = null, seoLanguage = "de")

Example:

{{ '/path/to/image' | rokka_stack_url('preview', seo='my-seo-image-url-fragment', seoLanguage = 'fr') }}

Example output: https://my-org.rokka.io/preview/123abcde/my-seo-image-url-fragment.jpg

rokka_original_size_url: create an image URL for rokka that outputs the original size

rokka_original_size_url(format = "jpg", seo = null, seoLanguage = "de")

The image will be in its original size, but optimized, compressed and delivered through the CDN of rokka.

rokka_resize_url: create an image URL for rokka with the dynamic stack to scale the image

rokka_resize_url(width, height = null, format = "jpg", seo = null, seoLanguage = "de")

The dynamic stack will make sure that the image is no wider than width and no higher than height.

rokka_resizecrop_url: create an image URL for rokka with the dynamic stack to scale and crop the image

rokka_resizecrop_url(width, height, format = "jpg", seo = null, seoLanguage = "de")

Similar to resize, but makes sure that the image always has the dimensions width and height. If the aspect ratio of the image does not fit, the longer side is cropped to fit into the dimensions.

rokka_add_options: change a rokka URL to add options

rokka_add_options(options)

This allows you to configure a stack on the fly and set stack options and variables.

Example:

{{ '/path/to/image' | rokka_stack_url('preview') | rokka_add_options('options-jpg.quality-80') }}
{{ '/path/to/image' | rokka_stack_url('preview') | rokka_add_options('resize-width-200') }}
{{ '/path/to/image' | rokka_stack_url('preview') | rokka_add_options('resize-width-200--options-jpg.quality-80') }}

rokka_src_attributes: change a rokka URL into a css fragment for retina images for css

rokka_src_attributes(multipliers = [2])

Example:

{{ '/path/to/image' | rokka_stack_url('large') | rokka_src_attributes }}

Example output: background-image:url('https://liip.rokka.io/stack/imagehash.jpg'); background-image: -webkit-image-set(url('https://liip.rokka.io/stack/imagehash.jpg') 1x, url('https://liip.rokka.io/stack/options-dpr-2/imagehash.jpg') 2x);

rokka_background_image_style: change a rokka URL into the HTML image tag fragments for retina

rokka_background_image_style(multipliers = [2])

Example:

{{ '/path/to/image' | rokka_stack_url('large') | rokka_background_image_style }}

Example output: src="https://org.rokka.org/stack/imagehash.jpg" srcset="https://org.rokka.org/stack/options-dpr-2/imagehash.jpg"

Twig functions

rokka_generate_url(hash, stack, format = "jpg", seo = null, seoLanguage = "de")

Output: A rokka URL for the specified image hash and stack, with the "seo"-filename, if specified.

Development

Running PHP-CS-Fixer

Running phpstan


All versions of twig with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1 || ^8.0
rokka/client Version ^1.3.1
twig/twig Version ^2.7 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rokka/twig contains the following files

Loading the files please wait ....