Welcome Guest, Not a member yet? Register   Sign In
Help on adding the Imagine Library in Codeignighter
#1

Hello everyone, long time user of CI but new to this forum.

I have been trying to integrate or add the Imagine Library into CI but have been very unsuccessful. Don't really get the "namespaces" and "use" concept I guess I just got use to CI that anything else just doesn't seem right.

Anyway if anyone can help I will really appreciated, and if anyone asks why not use CI image library well, I need more function specially when dealing with layers in animated gifs and pdfs and more control when it comes to rotating and other image manipulations that the basic CI image library can't do.

By the way I am using CI latest stable version 2.* can't wait for the stable 3.*

Again thank you in advance for anyone that can help.
Reply
#2

(This post was last modified: 01-27-2015, 04:24 AM by d1a8lo24.)

Just wanted to share with everyone how to implement the Imagine image library on their CI application.

Follow these steps.

1 download the Imagine Library at: https://github.com/avalanche123/Imagine

2 Copy the Imagine folder into your CI application libraries folder: application/libraries

3 Create a file and call it imagine_autoload.php

4 add the following code to the imagine_autoload.php file

PHP Code:
<?php

set_include_path
('/application/libraries/Imagine' PATH_SEPARATOR get_include_path());

function 
imagineLoader($class) {
    
$path $class;
    
$path str_replace('\\'DIRECTORY_SEPARATOR$path) . '.php';
    if (
strpos($class'Imagine') !== 0)
    {
        return;
    }
    include_once 
$path;
}

spl_autoload_register('\imagineLoader'); 

Now lets create the controller to do some image manipulation.

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Testing extends CI_Controller {

    function 
__construct()
    {
        
parent::__construct();
    }

    function 
index()
    {
        require_once(
'./application/libraries/imagine_autoloader.php');

        
$imagine = new \Imagine\Gd\Imagine();

        
$image $imagine->open('/path/to/image.jpg');
        
$thumbnail $image->thumbnail(new Imagine\Image\Box(100100));
        
$thumbnail->save('/path/to/thumnail_image.jpg');
    }


Now check the path of where the image was saved and you should find a thumbnail.

So get creative and read the documentation at: http://imagine.readthedocs.org/en/latest/
Reply
#3

(This post was last modified: 01-27-2015, 04:46 AM by sv3tli0.)

An advice ..
Make a Model Imagine and there init the library and make methods for the thing which you will need with just passing 1-2 variables.
Don't use this directly at Controller.

An one note - when you move to CI3 it has an option to use composer and with composer you wont need this solution as it has autoloader.
Best VPS Hosting : Digital Ocean
Reply
#4

(01-27-2015, 04:36 AM)sv3tli0 Wrote: An advice ..
Make a Model Imagine and there init the library and make methods for the thing which you will need with just passing 1-2 variables.
Don't use this directly at Controller.

An one note - when you move to CI3 it has an option to use composer and with composer you wont need this solution as it has autoloader.

As you can see the controller is for testing purposes. But in reality you can use the library anywhere you want. I was just showing how you implement the library in CI since I couldn't find any info on implementing the library. As always is up to the developer on how to use the information.

As far as composer, I am not really sure it would help since all it does is or what I think it does is download the files of a specific library to your application from there is up to you on how to apply it on your own application. But if it will go right up ahead and do the work for me then I can't wait for CI 3 to become stable to give it a try.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB