[eluser]Mat-Moo[/eluser]
Thanks for the spot on the errors  Yep, probably a couple of typos, can't spot any myself (odd!)
[eluser]Kevin Smith[/eluser]
Thanks for this library! It solved a specific problem I was having with resizing, but introduced a new one. With the stock Image Manipulation class, I could send the results of a photo upload ($_FILES['userfile']['tmp_name']) to the class for processing and it would just save it back to the temp file if I wanted. I ran into a problem with this library because it needed to see an extension on the filename in order to save it, and temp files uploaded by PHP don't have extensions. They *DO* have mime-types though. So... I tweaked the code to check its mime-type instead of its extension, remove the extensions if they exist, and add the proper extension to the saved filename. I would've submitted a pull request on Github, but I didn't see this library on there. Hope this helps:
Edit: I removed my code sample because it actually didn't work in some cases. I had to make more significant adjustments to the code, so it would be too tedious to copy the changes here and incredibly tedious to try to translate that into your code on your end. If this library ever goes up on Github I'll submit a pull request.
[eluser]Atas[/eluser]
Hello, thanks for this library!
It would be great if i could do this:
Code: $this->image_moo->set_background_colour("TRANSPARENT");
Take a look to resizeIntoBox function, if $transparent param is true fill with transparency the empty space.
Thanks again and sorry my english...
Code: class MY_Image_lib extends CI_Image_lib {
function resizeIntoBox($r=255,$g=255,$b=255, $transparent=true){
$orginal_aspect = $this->orig_width/$this->orig_height;
$required_aspect = $this->width/$this->height;
if($orginal_aspect >= $required_aspect){
$temp_width = $this->width;
$temp_height = $this->width / $orginal_aspect;
// Position the image
$xPos = 0;
$yPos = floor(($this->height - $temp_height) / 2);
} else {
$temp_width = $this->height * $orginal_aspect;
$temp_height = $this->height;
// Position the image
$xPos = floor(($this->width - $temp_width) / 2);
$yPos = 0;
}
// If resizing the x/y axis must be zero
$this->x_axis = 0;
$this->y_axis = 0;
// Create the image handle
if ( ! ($src_img = $this->image_create_gd()))
{
return FALSE;
}
// Create The Image
if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))
{
$create = 'imagecreatetruecolor';
$copy = 'imagecopyresampled';
}
else
{
$create = 'imagecreate';
$copy = 'imagecopyresized';
}
// Create
$dst_img = $create($this->width, $this->height);
// White...
imagefill ( $dst_img, 0, 0, imagecolorallocate ( imagecreatetruecolor ( 140, 140 ), $r, $g, $b ) );
if($transparent == true){
$this->image_type = 3;
imagecolortransparent ( $dst_img , imagecolorallocate ( $dst_img , $r , $g , $b ) );
}
// Move into workspace
$copy($dst_img, $src_img, $xPos, $yPos, $this->x_axis, $this->y_axis, $temp_width, $temp_height, $this->orig_width, $this->orig_height);
// Show the image
if ($this->dynamic_output == TRUE)
{
$this->image_display_gd($dst_img);
}
else
{
// Or save it
if ( ! $this->image_save_gd($dst_img))
{
return FALSE;
}
}
// Kill the file handles
imagedestroy($dst_img);
imagedestroy($src_img);
// Set the file to 777
@chmod($this->full_dst_path, 0777);
return TRUE;
}
}
[eluser]web-johnny[/eluser]
Looks very good library . I didn't used it yet but it looks promising. It has all that I wanted.
[eluser]Philo01[/eluser]
Great library! =)
I noticed that it doesn't support the resize of transparent PNG images at the time so for those who are interested in this, open image_moo.php and look for ( line 552 ):
Code: // if padding, fill background
if ($pad)
{
$col = $this->_html2rgb($this->background_colour);
$bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]);
imagefilledrectangle($this->temp_image, 0, 0, $tx, $ty, $bg);
}
Add the following below:
Code: imagealphablending($this->temp_image, false);
imagesavealpha($this->temp_image, true);
$color = imagecolorallocatealpha($this->temp_image, 0, 0, 0, 127);
imagefilledrectangle($this->temp_image, 0, 0, $this->width, $this->height, $color);
That should do it!
Kind regards,
Philo
[eluser]ClaudioX[/eluser]
Anyone knows how output de dinamic_save?
Between another thing, i try this:
Code: <img alt='$label'>image_moo->load($image_path)->resize(100,100)->save_dynamic()."'/>
but dont work..
[eluser]Mat-Moo[/eluser]
You can't do that I'm afraid (Well pretty sure). You will need a callback to your controller that sends the output back e.g. <img src="\controlle\sized\image_name" /> and that will output image headers and the resized image.
[eluser]ClaudioX[/eluser]
Thx the reply Mat!
So, always when i want to use the dynamic_save i need use somethink like ajax to load the images?
Thx again, see ya
[eluser]Mat-Moo[/eluser]
Don't need ajax jsut "<img src="/mycontroller/imagefunction/image_path">" although you would have to convert the filepath to something more browser friendly! If you can it's better to cache the resized image and just serve it direct, that wa the cpu only has to size it once and saves time (disk is cheap!)
[eluser]Mat-Moo[/eluser]
[quote author="Philo01" date="1303932815"]Great library! =)
I noticed that it doesn't support the resize of transparent PNG images at the time so for those who are interested in this, open image_moo.php and look for ( line 552 ):
Code: // if padding, fill background
if ($pad)
{
$col = $this->_html2rgb($this->background_colour);
$bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]);
imagefilledrectangle($this->temp_image, 0, 0, $tx, $ty, $bg);
}
Add the following below:
Code: imagealphablending($this->temp_image, false);
imagesavealpha($this->temp_image, true);
$color = imagecolorallocatealpha($this->temp_image, 0, 0, 0, 127);
imagefilledrectangle($this->temp_image, 0, 0, $this->width, $this->height, $color);
That should do it!
Kind regards,
Philo[/quote]
Where should this be added? after the pad code? I need ot work on keeping transparency data!
|