2017 © Pedro Peláez
 

symfony-bundle ontheio-bundle

onthe.io image cloud API integration.

image

devmachine/ontheio-bundle

onthe.io image cloud API integration.

  • Friday, January 5, 2018
  • by lakiboy
  • Repository
  • 1 Watchers
  • 0 Stars
  • 538 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

DevmachineOntheioBundle

Build Status Scrutinizer Code Quality SensioLabsInsight, (*1)

onthe.io image cloud API integration., (*2)

2017 update

i.onthe.io service is no longer available for public use. Consider integrating another image cloud provider., (*3)

Installation

Install this bundle using Composer. Add the following to your composer.json:, (*4)

{
    "require": {
        "devmachine/ontheio-bundle": "~1.0"
    }
}

Register bundle in the kernel:, (*5)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...

        new Devmachine\Bundle\OntheioBundle\DevmachineOntheioBundle(),
        new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(),
    ];
}

Update config:, (*6)

devmachine_ontheio:
    image:
        key: "your-key"
        secret: "your-secret"

Example usage

class MyController extends Controller
{
    /**
     * Upload remote URL to the cloud.
     */
    public function uploadUrlAction(Request $request)
    {
        // Get URL from request.
        $url = $request->query->get('url');

        // Upload image using URL.
        $result = $this->get('devmachine_ontheio.client.image')->uploadByUrl($url);

        // Key from image API - you can save this in DB.
        $key = $result->getKey();

        // Width of uploaded image.
        $width = $result->getWidth();

        // Height of uploaded image.
        $height = $result->getHeight();

        // Check if same URL was uploaded before.
        $new = $result->isNew();

        // You can render hosted URLs with image helper.
        return $this->render('PathToTemplate.html.twig', [
            // Hosted URL of original image.
            'url' => $this->get('devmachine_ontheio.helper.image')->url($key),

            // Resize image into 200x150.
            'thumbnail_url' => $this->get('devmachine_ontheio.helper.image')->resizeUrl($key, 200, 150),

            // Crop image into 150x150 starting from (50, 50).
            'avatar_url' => $this->get('devmachine_ontheio.helper.image')->cropUrl($key, 150, 150, 50, 50),
        ]);
    }

    /**
     * Upload image from file i.e. convert local file to hosted image.
     */
    public function uploadFileAction()
    {
        // Assuming $filepath is set.
        $result = $this->get('devmachine_ontheio.client.image')->uploadByFile($filepath);
    }
}

Twig helper

{# PathToTemplate.html.twig #}

Original:  <img src="{{ key | devmachine_ontheio_image_url }}" alt=""><br>
Thumbnail: <img src="{{ key | devmachine_ontheio_image_url(200, 150) }}" alt=""><br>
Avatar:    <img src="{{ key | devmachine_ontheio_image_url(150, 150, 50, 50) }}" alt="">

Note

The API docs suggests you can rotate and delete images. Albeit integration for these features was implemented, I wasn't able to achieve described functionality. You can examine ImageClient::rotate() and ImageClient::delete() methods., (*7)

Form integration

You can integrate image uploads right into your form., (*8)

class MyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('foo', 'text')
            ->add('bar', 'text')
            ->add('images', 'devmachine_ontheio_image_gallery')
        ;
    }
}

Bootstrap 3 theme:, (*9)

Gallery, (*10)

Only image uploads by URL is supported at the moment., (*11)

Gallery form type assumes following Javascript and CSS code is present:, (*12)

Example bower.json:, (*13)

{
    "dependencies": {
        "bootbox": "~4.4",
        "magnific-popup": "~1.0"
    }
}

The Versions

05/01 2018

dev-master

9999999-dev https://github.com/lakiboy/devmachine-ontheio-bundle

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image

05/01 2018

1.2.0

1.2.0.0 https://github.com/lakiboy/devmachine-ontheio-bundle

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image

25/09 2017

1.1.0

1.1.0.0 https://github.com/lakiboy/devmachine-ontheio-bundle

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image

26/05 2017

1.0.4

1.0.4.0 http://devmachine.net

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image

27/04 2016

1.0.3

1.0.3.0 http://devmachine.net

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image

23/12 2015

1.0.2

1.0.2.0 http://devmachine.net

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image

23/12 2015

1.0.1

1.0.1.0 http://devmachine.net

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image

12/09 2015

1.0.0

1.0.0.0 http://devmachine.net

onthe.io image cloud API integration.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitri Lakachauskis

cloud image