Image resize issue (2 in a row) - El Forum - 10-04-2009
[eluser]alexdemers[/eluser]
Hey,
I have been struggling for an hour with a dozen lines of code and I can't find the issue.
Code: // Do the thumbnailing
$thumb_config['image_library'] = 'gd2';
$thumb_config['source_image'] = $fullpath;
$thumb_config['create_thumb'] = true;
$thumb_config['maintain_ratio'] = true;
$thumb_config['master_dim'] = 'width';
$thumb_config['new_image'] = $path_fixed . 'images/products/thumbs/'.$filename;
$thumb_config['width'] = '48';
$thumb_config['thumb_marker'] = '_48';
print_r($thumb_config);
$this->image_lib->initialize($thumb_config);
$this->image_lib->resize();
$this->image_lib->clear();
$thumb_config['width'] = '125';
$thumb_config['thumb_marker'] = '_125';
print_r($thumb_config);
$this->image_lib->initialize($thumb_config);
$this->image_lib->resize();
The second thumbnail gets created successfully but the first one's "maintaint_ratio" property gets ignored completly.
Here's a screen shot of my I get: http://imgur.com/3ILzA.png
The _125 has 125x94 and the _48 has 48x768 which is the original height of the image.
What am I doing wrong here?
Thanks
Edit: Oh, and the output of print_r's are both the same:
Code: Array
(
[image_library] => gd2
[source_image] => /images/products/originals/nqpoiyad7avauacw.jpg
[create_thumb] => 1
[maintain_ratio] => 1
[master_dim] => width
[new_image] => /images/products/thumbs/nqpoiyad7avauacw.jpg
[width] => 48
[thumb_marker] => _48
)
Array
(
[image_library] => gd2
[source_image] => /images/products/originals/nqpoiyad7avauacw.jpg
[create_thumb] => 1
[maintain_ratio] => 1
[master_dim] => width
[new_image] => /images/products/thumbs/nqpoiyad7avauacw.jpg
[width] => 125
[thumb_marker] => _125
)
Image resize issue (2 in a row) - El Forum - 10-04-2009
[eluser]John_Betong[/eluser]
I had a similar problem quite a while ago while I was creating multiple thumbnails and solved it by putting a slight delay before and/or after initialize config;
Code: usleep(123) ; // Delay execution in microseconds
$this->image_lib->initialize($thumb_config);
Image resize issue (2 in a row) - El Forum - 10-07-2009
[eluser]alexdemers[/eluser]
Just tried that, I didn't work at all. I'm starting to give up on this...
Image resize issue (2 in a row) - El Forum - 10-07-2009
[eluser]John_Betong[/eluser]
[quote author="alexdemers" date="1254963088"]Just tried that, I didn't work at all. I'm starting to give up on this...[/quote]
http://johns-jokes.com/c_rabbit/
Check out the above link:
Here is the code:
Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// require APPPATH .'libraries/MY_skyhook.php';
class C_rabbit extends Controller
{
protected $filename, $fullpath;
//==============================================================
//==============================================================
function __construct()
{
parent::__construct();
}
//==============================================================
//
// accepts new parameters
// returns new configuration
//
//==============================================================
function _image_set($width)
{
// set the thumbnail parameters
$thumb_config['image_library'] = 'gd2';
$thumb_config['source_image'] = $this->fullpath .'/' .$this->filename;
$thumb_config['create_thumb'] = true;
$thumb_config['maintain_ratio'] = true;
$thumb_config['new_image'] = $this->filename;
$thumb_config['quality'] = 64;
$thumb_config['height'] = 48;
$thumb_config['master_dim'] = 'width';
$thumb_config['width'] = $width ;
$thumb_config['thumb_marker'] = '_' .$width;
// call the library and create thumbnail
$this->load->library('image_lib');
$this->image_lib->clear();
$this->image_lib->initialize($thumb_config);
if (! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
// display the results
$style = "
border:dotted 1px #f00;
padding:0.42em;
text-align:center;
margin:2em auto;
width:" .$width .'px';
$new_img = str_replace('.jpg', $thumb_config['thumb_marker'], $this->filename)
. '.jpg';
$result = "<img >fullpath .'/' .$new_img ."' style='$style' alt='rabbit' /><br />";
return $result;
}
//==============================================================
//
//
//
//==============================================================
function index()
{
$this->fullpath = APPPATH .'img';
$this->filename = 'rabbit_shadow.jpg';
$style = '
background:#cfc none; color:#00f;
width:42%; margin:0.42em auto;
text-align:center
';
$ci_post = 'http://ellislab.com/forums/viewthread/131042/#648306';
$link = "<a href='" .$ci_post ."'>" .$ci_post .'</a>';
echo "<div style='width:88%; margin:0 auto;text-align:center'>";
echo "<fieldset style='$style'><legend>" .$link .'</legend>';
$width = 48;
echo $this->_image_set($width * 1);
echo $this->_image_set($width * 2);
echo $this->_image_set($width * 3);
echo '</fieldset>';
require APPPATH . 'views/adverts/_google_728x15.php';
echo '</div>';
}//endfunc
}//endclass
Image resize issue (2 in a row) - El Forum - 12-02-2009
[eluser]hamzakhan[/eluser]
http://ellislab.com/forums/viewthread/136755/
please my problem on image rsize and post me
any possible reply
|