rid / image-bundle
Handle file uploads, create and manage thumbnails Symfony2
Installs: 66
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- doctrine/orm: >=2.3
- imagine/imagine: v0.4.1
- symfony/symfony: >=2.3,<3.0
Requires (Dev)
This package is not auto-updated.
Last update: 2020-01-05 15:39:39 UTC
README
Provides handling uploaded files and thumbnail creation, clean templates and flexible configuration.
Full documentation soon...
How it works
- Store file name in database in a string
- Replace PHP field representation from string to RidImage
- Automatically inject configuration to RidImage
- Automatically handle uploaded files according to configuration
- Maximum parameters in config file (not in entities, services or templates)
Twig Example:
# config.yml: 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
// 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
Installation
- Composer: "rid/image-bundle": "dev-master",
- AppKernel: new Rid\Bundle\ImageBundle\RidImageBundle(),
- Config.yml:
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 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
Step 4: In Your entity class:
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
->add('image', 'rid_image')
Also implemented:
- Manual handling of uploaded files
- Events
In future:
- frontend widgets (jcrop)
- grabbing from url
- more tests