Welcome Guest, Not a member yet? Register   Sign In
Resize images on the fly and output/display them in views
#1

[eluser]CARP[/eluser]
Hi ppl
I'm becoming crazy trying to make a function to output a resized image
- I want to display some images (resized) in a view

So, I've created a library with a function that resizes the images and does something like this

Code:
...elseif($the_ext == 'gif')
{
    header("Content-Type: image/gif");
    imagegif($newim);
}...

And, in my views... i have something like

Code:
<img >mylib->resize($imagepath, $maxw, $maxh); ?&gt;" />

But I see blanks... the imagepath is correct, the resize function works, the library loads...

Any ideas?
Thanks
#2

[eluser]ClaudioX[/eluser]
I use image_moo to do something like this. http://ellislab.com/forums/viewreply/908735/

Maybe its help
#3

[eluser]appleboy[/eluser]
Could you paste your all source code of library, controller and views?

or provide test url?
#4

[eluser]ClaudioX[/eluser]
This is my full set:

Controller:
Code:
public function get_image()
{

    $img = $this->uri->segment(4);
    $Nav = new Nav_class();
        
    $this->load->library('image_moo');

    $this->image_moo->clear_temp();                        
    $this->image_moo->clear();
        
    $img = $Nav->getSpecialChar($img);
    $img = $Nav->rote.$img;
        
    $this->image_moo
         ->load($img)
         ->resize(120,120)
         ->save_dynamic();
        
    if($this->image_moo->errors) print $this->image_moo->display_errors();
}

In model, to encode/decode the image name (for utf-8 images name):
Code:
public function setSpecialChar($string){
    return str_replace( '=', '', base64_encode( ($string) ) );
}
public function getSpecialChar($string){
    return utf8_decode( base64_decode($string) );
}

the img tag generation (in model):
Code:
$last_change = filemtime( utf8_decode($folder.$img) );
$link_thumb  = $this->rote.'get_image/'.$this->setSpecialChar($folder.$img)."?cache=$last_change";
#5

[eluser]CARP[/eluser]
Hi guys
Sorry for late response, but after reading all replies, tried using image_moo but no luck yet
I'm pasting you the code of my controller and view so you can give me a hand please:

Controller
http://snipt.org/xmkkj

View
http://snipt.org/xmkkk

Logic:
- Controller loads a classifieds model and gets a random featured
- Controller loads the featured view with the data obtained from model
- View shows featured classified with its image (the image calls again to a function in pub controller)

My problem is that the image is not displayed (although i call the function alone and i can save the image from firefox correctly so the lib works)

Thanks again
#6

[eluser]appleboy[/eluser]
I think that the error occur on your views.
Code:
&lt;?php
    $imagencargar = getcwd()."\\".$rowimage->imagen_default;
    if (file_exists($rowimage->imagen_default) == TRUE)
    {
?&gt;
        <img border="0" src="&lt;?php echo site_url(" alt="" title="" />
&lt;?php
    }
    else
    {
?&gt;
    <img src="&lt;?php echo base_url(); ?&gt;/archivos/imagenes/default.png" />
&lt;?php
    }
?&gt;

you can print site_url("pub/getimg/$imagencargar") string, and check files exists?

please check or replace the following code.

Code:
$imagencargar = getcwd()."\\".$rowimage->imagen_default;
#7

[eluser]CARP[/eluser]
I know i'm playin dirty sending imagepath as a parameter of the controller's function
Is there a way to encode in md5 or something similar and decode in the controler function? I guess that way there won't be error about characters, etc. Am I right?

Thanks
#8

[eluser]ClaudioX[/eluser]
If i understand correctly, look my previous reply, this is why i use base_64 and utf8_encode.
#9

[eluser]CARP[/eluser]
Hi people
Doing the changes you proposed, encoding the path in base64, etc. made everything to work
Thanks !!!

http://i.imgur.com/UNni3.jpg




Theme © iAndrew 2016 - Forum software by © MyBB