dev-master
9999999-dev https://github.com/r1dd1ck777/image_bundleHandle file uploads, create and manage thumbnails Symfony2
MIT
The Requires
The Development Requires
by Ruslan Palagin
file symfony2 image thumbnail
Handle file uploads, create and manage thumbnails Symfony2
Provides handling uploaded files and thumbnail creation, clean templates and flexible configuration. , (*1)
``` yaml, (*2)
rid_image: presets: user_avatars: path: uploads/user/avatars/ default: image/default-user-avatar.png thumbnails: medium: default: image/default-user-avatar-90.png width: 90 height: 90 type: inset tiny: default: image/default-user-avatar-30.png width: 30 height: 20 type: outbound fields: Some\Bundle\Entity\User: avatar: user_avatars, (*3)
``` php // Twig: // simply find user and then: {{ asset(user.avatar) }} // /uploads/user/avatars/random_name.jpg (full size) {{ asset(user.avatar.small) }} // /uploads/user/avatars/small_random_name.jpg (90x90) {{ asset(user.avatar.tiny) }} // /uploads/user/avatars/tiny_random_name.jpg (30x20) // if image field is empty: {{ asset(user.avatar) }} // /image/default-user-avatar.png {{ asset(user.avatar.small) }} // /image/default-user-avatar-90.png {{ asset(user.avatar.tiny) }} // /image/default-user-avatar-30.png
``` yaml doctrine: dbal: types: rid_image: Rid\Bundle\ImageBundle\DBAL\Types\RidImageType rid_file: Rid\Bundle\ImageBundle\DBAL\Types\RidFileType mapping_types: rid_image: rid_image rid_file: rid_file, (*4)
rid_image: presets: # here you can create as many presets as you need somePresetName: path: uploads/category/ thumbnails: small: # define eny name for thumbnails width: 120 height: 70 # add more thumbnails fields: Some\Bundle\Entity\Category: fieldName: somePresetName # add more fields # add more classes, (*5)
Step 4: In Your entity class: ``` php namespace Some\Bundle\Entity\Category; use Doctrine\ORM\Mapping as ORM; use Rid\Bundle\ImageBundle\Model\RidImage; / * @ORM\Table() * @ORM\Entity() */ class Category { / * @ORM\Column(type="rid_image", length=255, options={"default" = ""}) */ protected $image; public function __construct() { $this->image = new RidImage(); } public function getImage() { return $this->image; } public function setImage($image) { $this->image = $image; } }
Step 5: Set field type in form builder
php
->add('image', 'rid_image')
, (*6)
Handle file uploads, create and manage thumbnails Symfony2
MIT
file symfony2 image thumbnail