1
I created a library
that resizes an image that I enter the name, but it’s happening that I need the same image resize to 3 different dimensions, so I made the code
php image. (library)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Imagem{
public function GerarImagem($imagem, $largura, $altura){
$CI =& get_instance();
$config = array();
$config['image_library'] = 'gd2';
$config['source_image'] = 'uploads/'.$imagem;
$config['new_image'] = 'uploads/'.$altura.'x'.$largura.'_'.$imagem;
$config['maintain_ratio'] = true;
$config['width'] = $largura;
$config['quality'] = "100%";
$config['height'] = $altura;
$CI->load->library('image_lib', $config);
$CI->image_lib->resize();
return $altura.'x'.$largura.'_'.$imagem;
}
}
?>
And I call her on model
thus:
$miniatura = $this->imagem->GerarImagem($foto_array['file_name'], 110, 110);
$media = $this->imagem->GerarImagem($foto_array['file_name'], 438, 438);
$grande = $this->imagem->GerarImagem($foto_array['file_name'], 720, 720);
The name of the images is inserted in the MySQL
, only when doing the resizing it only creates 1 image with the new dimension, which would be the first one I called 110x110, the rest does not create in the folder.
Change
$CI->image_lib->resize();
forif ( ! $CI->image_lib->resize())
{
 echo $CI->image_lib->display_errors();
}
and tell me if anything comes up.– Guilherme Nascimento
@Guilhermenascimento the first he resizes of good, but the remaining he returns
Your server does not support the GD function required to process this type of image
. And they’re all jpg– Alisson Acioli
Alisson I know this is not a place to criticize technologies, but the error message is a BUG, sorry but it’s a reason I avoid using the IC, It may be that I’m wrong, but it seems to me. Anyway I’ll test, tell me this using CI3?
– Guilherme Nascimento
No, CI2.. But I solved the problem, thanks!
– Alisson Acioli