- PlaceholderBundle
- What is this bundle?
- Installation
- Configuration
- Usage
- Contributions
- bernhard-webstudio/placeholder-bundle for enterprise
Use this bundle if you are looking for an easy way to generate beautiful placeholders or thumbnails for your project.
Do you provide a site with pages full of images? Do you use a lazy-loader with a grey-only image? Then this bundle is something for you respectively your site!
Depending on your configuration and your local environment, you can let the bundle return placeholders generated with Primitive or sqip.
You need to have the service installed which you want to use. Refer to their webpages linked above to get the installation guide. To install this bundle, refer to the following guide.
(This installation type is not yet supported. Please refer to the next installations instructions or create a recipe.) Open a command console, enter your project directory and execute:
$ composer require bernhard-webstudio/placeholder-bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require bernhard-webstudio/placeholder-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new BernhardWebstudio\PlaceholderBundle\BernhardWebstudioPlaceholderBundle(),
);
// ...
}
// ...
}
The standard configuration, which can be overriden as usual with Symfony bundles, looks like this:
bewe_placeholder:
service: 'bewe_placeholder.generator.primitive'
bin: 'primitive'
node_bin: 'node'
iterations: 10
output_path: ~
load_paths:
- "."
You can change the service to bewe_placeholder.generator.sqip
if you prefer to use sqip or even
to your own service, as long as it implements BernardWebstudio\PlaceholderBundle\Services\PlaceholderGeneratorInterface
.
To get the path to a placeholder of an image, request the bewe_placeholder.provider
service.
On this object, call getPlaceholder($imagepath)
with the path to your image as argument. As a second
Parameter, you could pass the mode what you want in return, such as 'raw', 'base64', 'url' or 'path'.
Defaults to 'path'.
To force generatation of an image, the service bewe_placeholder.generator
can be used. Pass
as arguments the input and the output path to the function generate($input, $output)
.
Be aware that the services do not have to output a file exactly to your output path.
Instead, they usually append .svg
. This is dependent on the service: call getOutputExtension
to get the extension.
Use the placeholder
Twig filter. Apply it on the path of your image. You can optionally pass
an additional parameter, such as 'raw', 'base64', 'url' or 'path' to specify how you want the image served.
Raw returns the files content, base64 gets you the base64 encoded files content, url returns
the optimized src-attribute (svg as svg, other images as base64, all ready to serve as src=
-attribute value)
and with path you get the path to the placeholder image.
If you are just interested in an URL of the image, refer to the next section.
If you configure to include the routing file provided by this bundle, you can generate
a route named bewe_placeholder
with the parameter imagePath
. This URL will provide you
with the placeholder, default lazyly generated. The routing file can be included in your
routing.yml like this, for example:
bewe_placeholder_urls:
resource: "@BernhardWebstudioPlaceholderBundle/Resources/config/routing.yaml"
If you have performance concerns, use the bewe:placeholder:prepare
command to generate placeholders for all
the images in your load_paths. The option --dry enables you to see which images would be generated and can be used
to test your configuration.
Contributions are welcome. Just open a PR!
Available as part of the Tidelift Subscription
The maintainers of bernhard-webstudio/placeholder-bundle and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.