Resizing an image on the fly in CodeIgniter without using CI image manipulation functions

1.7k Views Asked by At

I am trying to resize an image that is being fetched from a location on the server.

The CI image manipulation method works very good. But i need something like this

localhost/images/hello.jpg -width=500&height=450

or

localhost/images/imageresizer?path=http://localhost/images/hello.png&width=500&height=450

I know the first one looks wiered, but i just want to know if any other good methods exists other than image_lib in CI

Using Ci image_lib the image simply displays on the browser, but rather than displaying it i need to output a url to the image in json. So that front-end developers can display them on their devices

please suggest

Thank you.

2

There are 2 best solutions below

0
On
function resize($path="", $width="", $height="", $type=""){
    if($path AND $width AND $height AND $type){
        $decoded_path = base64_decode($path);
        //resize
        header("Content-type:image/$type");
        echo $image;
    }
}

--

$image_path = "/var/www/images/test.png";

<img src="<?php echo "http://example.com/app/resize/" . base64_encode($image_path) . "/500/200/png"; ?>" alt="my resized image">
0
On

Try this out Codeigniter Advanced Images. It has worked perfectly for me. You only have to note that the uploads folder has to be in the same location as the index.php page. Also, the folder name and controller name have to be the same. Cheers.