2017 © Pedro Peláez
 

symfony-bundle image-bundle

Handle file uploads, create and manage thumbnails Symfony2

image

rid/image-bundle

Handle file uploads, create and manage thumbnails Symfony2

  • Sunday, October 20, 2013
  • by mrriddick7@gmail.com
  • Repository
  • 1 Watchers
  • 0 Stars
  • 60 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

RidImageBundle (beta)

Provides handling uploaded files and thumbnail creation, clean templates and flexible configuration. Build Status, (*1)

Full documentation soon...

How it works

  1. Store file name in database in a string
  2. Replace PHP field representation from string to RidImage
  3. Automatically inject configuration to RidImage
  4. Automatically handle uploaded files according to configuration
  5. Maximum parameters in config file (not in entities, services or templates)

Twig Example:

``` yaml, (*2)

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, (*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

Installation

  1. Composer: "rid/image-bundle": "dev-master",
  2. AppKernel: new Rid\Bundle\ImageBundle\RidImageBundle(),
  3. Config.yml:

``` 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)

Also implemented:

  • Manual handling of uploaded files
  • Events

In future:

  • frontend widgets (jcrop)
  • grabbing from url
  • more tests

The Versions

20/10 2013

dev-master

9999999-dev https://github.com/r1dd1ck777/image_bundle

Handle file uploads, create and manage thumbnails Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan Palagin

file symfony2 image thumbnail