Part of the EllisLab Network
   
 
Image lib improvements
Posted: 15 February 2008 06:27 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  597
Joined  04-20-2006

Hi,

I personally think some work must be done on the image library like:
- The ability to watermark with transparent PNG (it’s actually not handling alpha transparency)
- The ability to watermark with ImageMagick
- The ability to choose where to place the thumb_marker, for example I would like that I can choose to place it before the file extension.

 Signature 

All CodeIgniter resources in 1 place?
http://www.codeigniterdirectory.com (Did you know we are converting this directory to Linkster? We need a Graphic designer, join us!)

My website: Création de sites Genève, Too Pixel

Profile
 
 
Posted: 16 February 2008 05:44 AM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  2795
Joined  07-14-2006

I like to add
- defining the dimensions of the thumbnail in the image_lib config (now you can create a thumbnail but it has the same size of the manipulated image)

Profile
 
 
Posted: 18 February 2008 08:32 AM   [ Ignore ]   [ # 2 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6475
Joined  03-23-2006

These are all great suggestions.  Elitemedia… do you have a proof of concept, or some code we could look at?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
 
 
Posted: 18 February 2008 09:14 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  597
Joined  04-20-2006

About ImageMagick not because I don’t know very well this software (that’s why it’s wonderfull for me to have CI’s driver for it!) But this is one library for watermarking with GD that work perfectly:

<?php

class waterMarker
{
  
function watermark($sourcefile, $watermarkfile) {
  
   
#
   # $sourcefile = Filename of the picture to be watermarked.
   # $watermarkfile = Filename of the 24-bit PNG watermark file.
   #
   
   //Get the resource ids of the pictures
   
$watermarkfile_id = imagecreatefrompng($watermarkfile);
   
   
imageAlphaBlending($watermarkfile_id, false);
   
imageSaveAlpha($watermarkfile_id, true);

   
$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));

   switch(
$fileType) {
       
case('gif'):
           
$sourcefile_id = imagecreatefromgif($sourcefile);
           break;
           
       case(
'png'):
           
$sourcefile_id = imagecreatefrompng($sourcefile);
           break;
           
       default:
           
$sourcefile_id = imagecreatefromjpeg($sourcefile);
   
}

   
//Get the sizes of both pix  
  
$sourcefile_width=imageSX($sourcefile_id);
  
$sourcefile_height=imageSY($sourcefile_id);
  
$watermarkfile_width=imageSX($watermarkfile_id);
  
$watermarkfile_height=imageSY($watermarkfile_id);
   
   
$dest_x = $sourcefile_width - $watermarkfile_width;
   
$dest_y = $sourcefile_height - $watermarkfile_height;
   
   
// if a gif, we have to upsample it to a truecolor image
   
if($fileType == 'gif') {
       
// create an empty truecolor container
       
$tempimage = imagecreatetruecolor($sourcefile_width,
                                                                           
$sourcefile_height);
       
       
// copy the 8-bit gif into the truecolor image
       
imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0,
                           
$sourcefile_width, $sourcefile_height);
       
       
// copy the source_id int
       
$sourcefile_id = $tempimage;
   
}

   imagecopy
($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,
                       
$watermarkfile_width, $watermarkfile_height);

   
//Create a jpeg out of the modified picture
   
switch($fileType) {
   
       
// remember we don't need gif any more, so we use only png or jpeg.
       // See the upsaple code immediately above to see how we handle gifs
       
case('png'):
           
imagepng ($sourcefile_id, $sourcefile);
           break;
           
       default:
           
imagejpeg ($sourcefile_id, $sourcefile);
   
}          
  
   imagedestroy
($sourcefile_id);
   
imagedestroy($watermarkfile_id);
   
   
}
}
?>

Also, not to say you have to take it or make spy on them, but you may look at Kohana image lib, there is some good code to look at there.

 Signature 

All CodeIgniter resources in 1 place?
http://www.codeigniterdirectory.com (Did you know we are converting this directory to Linkster? We need a Graphic designer, join us!)

My website: Création de sites Genève, Too Pixel

Profile
 
 
Posted: 18 February 2008 09:19 AM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6475
Joined  03-23-2006

OK cool.  If this is your code, and you’re willing to have this into CI, what we’ll need is the following.

1) a MY_image_lib.php for testing purposes
2) existing methods need to be over-ridden so that we can all run drop-in tests
3) the coding style would need to change to match CodeIgniter’s (reference)
4) we would need to benchmark it, particularly against the current implementation.  Is it faster? Slower? How much?
5) we would need to test it against PHP 4 and 5
6) we would need at least 6 or 8 people to test it
7) we would need documentation and some examples written up

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
 
 
Posted: 18 February 2008 10:20 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  597
Joined  04-20-2006

As I see Derek, there is already in the image lib a PNG watermarker (the same is in Expression Engine too) but it’s simply doesn’t work with alpha transparency PNG. I am sure it was written to handle this transparency, but it’s just simply a bug of the library. So why should we try rewrite a new thing when it’s just question of making work properly what is existing already?

Also, for those who are interrested trying the library above, here is a quick and simple like hell use of it with CI:

// Loads the library (Only GD2 actually)
$this->load->library('Watermarker');

$overlay_pic = 'public/images/watermark.png'; // 24 bit transparent PNG
$source_pic  = 'upload/your_pic_to_watermark.jpg'; // A fresh uploaded and resized picture. Note: folder must be CHMOD 777 before use watermarker

// Watermark picture
// It will simply overwrite the $source_pic with the watermarked one.
$this->watermarker->watermark($source_pic, $overlay_pic);

 Signature 

All CodeIgniter resources in 1 place?
http://www.codeigniterdirectory.com (Did you know we are converting this directory to Linkster? We need a Graphic designer, join us!)

My website: Création de sites Genève, Too Pixel

Profile
 
 
Posted: 18 February 2008 10:31 AM   [ Ignore ]   [ # 6 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6475
Joined  03-23-2006

So why should we try rewrite a new thing when it’s just question of making work properly what is existing already?

Um, you shouldn’t.  Your suggestions were listed in the feature request forum, and your posts implied to me that this was additional functionality that needed to be added.  If you think its a bug, then I’d welcome your input in tracking it down.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
 
 
Posted: 18 February 2008 10:38 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  597
Joined  04-20-2006

For the PNG problem I agree, this is a bug. Posted:
http://codeigniter.com/forums/viewthread/71962/

For other points I mentioned, it’s feature requests.

 Signature 

All CodeIgniter resources in 1 place?
http://www.codeigniterdirectory.com (Did you know we are converting this directory to Linkster? We need a Graphic designer, join us!)

My website: Création de sites Genève, Too Pixel

Profile
 
 
Posted: 18 February 2008 10:42 AM   [ Ignore ]   [ # 8 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6475
Joined  03-23-2006

OK, so then for the feature requests, is this something you’re willing to help code?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
 
 
Posted: 18 February 2008 10:47 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  597
Joined  04-20-2006

I could try this one:
- The ability to choose where to place the thumb_marker, for example I would like that I can choose to place it before the file extension.

But as I am now in a work rush period, I can’t do that right now. I take note that I must do this then I will PM you when I have something working, is it ok like that?

 Signature 

All CodeIgniter resources in 1 place?
http://www.codeigniterdirectory.com (Did you know we are converting this directory to Linkster? We need a Graphic designer, join us!)

My website: Création de sites Genève, Too Pixel

Profile
 
 
Posted: 18 February 2008 10:49 AM   [ Ignore ]   [ # 10 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6475
Joined  03-23-2006

That sounds super!  I can’t tackle these right now either due to work crunch, but I’m sure between us, and the rest of the community we could get some nice stuff working.  Can’t wait.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 60641 Total Logged-in Users: 38
Total Topics: 73016 Total Anonymous Users: 0
Total Replies: 393628 Total Guests: 424
Total Posts: 466644    
Members ( View Memberlist )