2017 © Pedro Peláez
 

library simple-photo

Photo uploading and management made easy.

image

morrelinko/simple-photo

Photo uploading and management made easy.

  • Saturday, July 12, 2014
  • by morrelinko
  • Repository
  • 2 Watchers
  • 10 Stars
  • 58 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

SimplePhoto

Handling photos in your web application has never been so simple., (*1)

Build Status, (*2)

Installation

Through Composer, (*3)

{
    "require": {
        "morrelinko/simple-photo": "0.*"
    }
}

Create the database using the schema below for the data store you will be using, (*4)

Uploading Photo

$photoId = $simplePhoto->uploadFromPhpFileUpload($_FILES["image"]);
// Or
$photoId = $simplePhoto->uploadFromFilePath("/path/to/photo.png");

With support for accepting uploads from different sources., (*5)

$photoId = $simplePhoto->upload(new YourUploadSource($imageData));

The two upload methods shown above actually are aliases/shortcuts for doing this, (*6)

$photoId = $simplePhoto->upload(new PhpFileUploadSource($_FILES["image"]));
// Or
$photoId = $simplePhoto->upload(new FilePathSource("/path/to/photo.png"));

Retrieving Photo

$photo = $simplePhoto->get($photoId);

$photo->id();
$photo->url();
$photo->path();
$photo->fileMime();
$photo->storage();
$photo->fileSize();
$photo->fileExtension();
$photo->filePath();
$photo->createdAt();
...

Setup

SimplePhoto requires..., (*7)

  • Storage Manager: For Storing & Managing registered storage adapters.
  • Data Store: Database for persisting information about a photo.
use SimplePhoto\Storage\LocalStorage;
use SimplePhoto\StorageManager;
use SimplePhoto\DataStore\SqliteDataStore;
use SimplePhoto\SimplePhoto;

// Create a local storage adapter
$localStorage = new LocalStorage('/path/to/project/root/', 'photos');

// Create a storage manager
$storageManager = new StorageManager();

// Adds one or more registered storage adapters
$storageManager->add('local', $localStorage);

// Create Data Store
$dataStore = new SqliteDataStore(['database' => 'photo_app.db']);

// Create Our Simple Photo Object
$simplePhoto = new SimplePhoto($storageManager, $dataStore);

Get photos (+Transformation)

If you want to get a re-sized photo, use the "transform" options of the second argument, (*8)

$photo = $simplePhoto->get($photoId, [
    'transform' => [
        'size' => [200, 200]
    ]
]);

The default transformation options available..., (*9)

[
    'size' => [$width, $height]
    'rotate' => [$angle, ($background)]
]

You could implement your own transformer and add more transformation options, (*10)

Arguments in parenthesis are optional, (*11)

Collection of photos

$photos = $simplePhoto->collection([2, 23, 15]);

$photos->get(0); // gets photo '2'
$photos->get(1); // gets photo '23'

PhotoCollection come with a handful of methods for manipulating its items, (*12)

// Creates a collection of photos
$photos = $simplePhoto->collection([2, 23, 15, 34, 21, 1, 64, 324]);

// Gets all as array
$allPhotos = $photos->all();

// Uses filter() method.
// This example creates a new photo collection containing only photos in 'local' storage
$localPhotos = $photos->filter(function($photo) {
    return $photo->storage() == 'local';
});

var_dump($localPhotos);

Push

// Probably gotten from a db
$users = [
    ['user_id' => 1, 'name' => 'John Doe', 'photo_id' => 2],
    ['user_id' => 2, 'name' => 'Mary Alice', 'photo_id' => 5]
];

$simplePhoto->push($users, array('photo_id'));

var_dump($users);

// Sample Output:
[
    ['user_id' => 1, 'name' => 'John Doe', 'photo_id' => 2, 'photo' => (Object SimplePhoto\PhotoResult)],
    ['user_id' => 2, 'name' => 'Mary Alice', 'photo_id' => 5, 'photo' => (Object SimplePhoto\PhotoResult)]
];

If you would like complete control on what is pushed to the array from the photo result,, (*13)

you specify a callback as third argument to push(), (*14)


$simplePhoto->push($users, array('photo_id'), function(&$item, $photo, $index, $name) { $item['photo_url'] = $photo->url(); }); var_dump($users); // Sample Output: [ ['user_id' => 1, 'name' => 'John Doe', 'photo_id' => 2, 'photo_url' => 'http://example.com/files/2014/xxxxx.png'], ['user_id' => 2, 'name' => 'Mary Alice', 'photo_id' => 5, 'photo_url' => 'http://example.com/files/2014/xxxxx.png'] ];

Supported Photo Sources

Supported Data Stores

Supported Storage

TODO

  • Add MongoDB Data Store

Credits

This code is principally developed and maintained by [Laju Morrison] (https://github.com/morrelinko), (*15)

Licence

The MIT License (MIT). Please see License File for more information., (*16)

Supported by http://contactlyapp.com, (*17)

The Versions

12/07 2014

dev-feature-gravatar-storage

dev-feature-gravatar-storage

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

upload image photo transform storage simple-photo

22/06 2014

dev-master

9999999-dev

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

upload image photo transform storage simple-photo

22/06 2014

0.7.0

0.7.0.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

upload image photo transform storage simple-photo

01/05 2014

dev-develop

dev-develop

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

upload image photo transform storage simple-photo

18/04 2014

0.6.0

0.6.0.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/04 2014

0.5.0

0.5.0.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

20/02 2014

0.4.0

0.4.0.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/02 2014

0.3.1

0.3.1.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/01 2014

0.3.0

0.3.0.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

27/01 2014

0.2.1

0.2.1.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

20/01 2014

0.2.0

0.2.0.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

14/01 2014

0.1.0

0.1.0.0

Photo uploading and management made easy.

  Sources   Download

MIT

The Requires

  • php >=5.3.0