dev-master
9999999-dev http://github.com/Zertz/ZertzPhotoBundleSymfony ZertzPhotoBundle
MIT
The Requires
photo management
Wallogit.com
2017 © Pedro Peláez
Symfony ZertzPhotoBundle
This bundle provides an easy to use platform to automatically resize photos on upload and display them back to the user., (*1)
In composer.json, add:, (*2)
"require": {
"zertz/photo-bundle": "dev-master"
}
Run an update to install the bundle:, (*3)
php composer.phar update zertz/photo-bundle
Enable the bundle:, (*4)
public function registerBundles()
{
$bundles = array(
new Zertz\PhotoBundle\ZertzPhotoBundle(),
);
}
Add the following lines:, (*5)
# Twig Configuration
twig:
form:
resources:
- ZertzPhotoBundle:Form:fields.html.twig
# ZertzPhotoBundle Configuration
zertz_photo:
directory: /path/to/save/to
domain: http://img.yourdomain.com
quality: 70
formats:
small:
size: { width: 140 , height: 87 }
medium:
size: { height: 175 }
large:
size: { width: 635 }
quality: 90
Note, (*6)
directoryanddomainkeys are required. For JPEG photos, thequalitysetting is customizable, but defaults to 70., (*7)
Formats, (*8)
formatsare customizable and thesizeproperty may contain one of, or both,widthandheight. The photo will automatically be resized and the aspect ratio is always maintained. For JPEG photos, the optionalqualitysetting overrides the globalqualitysetting., (*9)If no
formatsare defined, then the original photo is simply uploaded., (*10)
This bundle provides the basics for persisting a photo object to the database.
It is your role however to extend the Photo class and add any fields you deem
useful., (*11)
To get started, your entity class should look like this:, (*12)
<?php
// src/Acme/PhotoBundle/Entity/Photo.php
namespace Acme\PhotoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zertz\PhotoBundle\Entity\Photo as BasePhoto;
/**
* @ORM\Entity
* @ORM\Table(name="zertz_photo")
*/
class Photo extends BasePhoto
{
/**
* @ORM\Column(name="ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
public function __construct() {
parent::__construct();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
Finally, run the following command to update the database schema:, (*13)
php app/console doctrine:schema:update --force
The bundle provides simple helpers to upload and display photos., (*14)
In a form, add the format option and the bundle will automatically take care
of the rendering:, (*15)
->add('file', 'file', array(
'format' => 'small',
))
In a Twig template, add the path filter and specify the format to display:, (*16)
<img src="{{ photo|path('medium') }}">
If the photo doesn't appear at all, then the format request in your form doesn't exist. Otherwise, if the format exists, you should regenerate thumbnails manually using the following command:, (*17)
php app/console zertz:photo:generate myformat
or, (*18)
php app/console zertz:photo:generate --all
Symfony ZertzPhotoBundle
MIT
photo management