EllisLab text mark
Advanced Search
1 of 7
1
   
Image Moo - Image manipulation library
Posted: 20 July 2010 11:10 AM   [ Ignore ]
Avatar
Joined: 2008-10-20
397 posts

Updated to 0.9.2, fixed a couple of minor bugs :-
Full details and download now at
http://www.matmoo.com/codeigniter/image_moo/

The CI library for image manipulation is great, but I found it awkward to use when doing multiple processes. So I wrote my own library which I’m happy for you to play with and send feedback. It is limited to PHP 5 and GD2 only, sorry, but that suits my needs.
Example :-

$this->load->library('image_moo');
    
// single thumbnail
    
$this->image_moo
        
->load("myfile.x")
        ->
resize(200,200)
        ->
save("thumb.x");
    if (
$this->image_moo->error) print $this->image_moo->display_errors();

    
// thumbnail and large, large watermarked
    
$this->image_moo
        
->load("myfile.x")
        ->
resize(240,200)
        ->
save("thumb.x")
        ->
resize(1024,768)
        ->
save("medium.x")
        ->
resize(1600,1024)
        ->
save("large.x");
    if (
$this->image_moo->error) print $this->image_moo->display_errors();

    
// add watermarks
    
$this->image_moo
        
->load("myfile.x")
        ->
load_watermark("image.x")
        ->
resize(240,200)
        ->
save("thumb.x")
        ->
resize(1024,768)
        ->
watermark(2)
        ->
save("medium.x")
        ->
resize(1600,1024)
        ->
watermark(8)
        ->
save("large.x");
    if (
$this->image_moo->error) print $this->image_moo->display_errors();

    
// create watermark text
    
$this->image_moo
        
->load("myfile.x")
        ->
make_watermark_text("copyright me","font.ttf")
        ->
resize(1024,768)
        ->
watermark(2)
        ->
save("medium.x");
    if (
$this->image_moo->error) print $this->image_moo->display_errors(); 

Those are a couple of basic uses but it has a couple of extras for resize smile
resize($max_width,$max_height,$pad=FALSE)
So resize will work as normal, e.g. an image of 1000 x 600. resize(200,200) your output image would be 200 x 120. Sometimes you want this as a square image, so set pad and the returned image will be 200 x 200 and the image centralised on to it. The background colour can be set with $this->image_moo->set_background_colour($html_colour=”#ffffff”) (default is white #ffffff.
There is also another resize, resize_crop($x,$y) which is similar to resize but truncates the original image to get the largest part in the resize. e.g. a 1000 x 600 image resize_crop(200,200) returns a 200 x 200 image, but the source will be the centralised 600 x 600 part of the main image (does that sound right?!)

There are no docs at the moment as this is just version 0.7.2 while I continue the project I need this for, but all feedback is welcome.
——————————————————————————————
load($filename)
Loads a master image in for manipulation
save($filename, $overwrite=FALSE)
Saves the altered image (original if applicable) to file, will only overwrite if $overwrite=TRUE
save_dynamic($filename=”“)
Send the altered image to the screen, use filename to specify how it should be written, default is jpg
load_watermark($filename)
Loads a file to use as a watermark
——————————————————————————————
TBC

Edit : updated to 0.8.9

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 20 July 2010 11:12 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

Ah yea watermark(x) work with the num pad key system, so 789 position it across the top, left to right, 456, middle and 123 at the bottom. You can also set transparency level $this->image_moo->set_watermark_transparency(50). You can also set the jpg quality for image save, $this->image_moo->set_jpeg_quality(75);

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 24 July 2010 07:01 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

Updated to 0.7.2 added dynamic output smile

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 24 July 2010 07:23 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-07-04
6 posts

THANKS A LOT FOR THIS LIBRARY ... IT’S SUPERLATIVE

 
Posted: 25 July 2010 04:09 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2009-05-16
72 posts

good work mat, this library is practical. i have an algorithm i created to create thumbnails while resizing the image to specific height and width dimensions (it actually cuts some of the image off, but does it in an “intelligent” way as to take a best guess at where the content of the image is). would you be interested in incorporating this into your library? let me know and i can send you the code.

i have successfully incorporated it into several social media sites that i have worked on.

 Signature 

sr web applications developer
ci, mysql driven, jquery powered (mostly social web applications)

taky.bz, blackhat

 
Posted: 25 July 2010 04:28 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

That sounds interesting, could add it as an option to the resize_crop function (Add Tru for best guess of content location)

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 25 July 2010 10:54 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2009-05-16
72 posts

yeah it is great for social media sites where you need the thumbnails to be the EXACT same size, like 60x60 pixels for instance so they can line up neatly next to eachother. alternatively you would usually just maintain the aspect ratio (width, usually) and it will mess up the page’s layout significantly. i can grab the code from one of my projects soon and post it for you.

what it does is resizes it to 60x while maintain the aspect ratio of the longest dimension. after that it takes the other dimension and positions the cropped region in the center of the image. it produces thumbnails that are comparable to facebook (really, i have compared it with facebook’s automatic cropping and the images almost always crop at the same spot so i am sure they are using a similar algo).

i’ll unzip this big archive (like 50gb, its an entire social media application i wrote with the whole database in tact, around 150 thousand users, so it will take a fair bit of time) and find the library that does it in a moment.

 Signature 

sr web applications developer
ci, mysql driven, jquery powered (mostly social web applications)

taky.bz, blackhat

 
Posted: 26 July 2010 05:09 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

Yep, my resize_crop does the same thing (exact size, largest crop and resize), except it centralises the crop location and does not work out the best position for it. Would be a great addition though!

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 26 July 2010 07:32 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2009-05-16
72 posts

damn you mat-moo, that i what mine does as well. i wonder if it would actually be possible to detect a skin-tone (like a variation of brown) and try to narrow down where the content of the image is that way with either imagemagick or the codeigniter library smile

 Signature 

sr web applications developer
ci, mysql driven, jquery powered (mostly social web applications)

taky.bz, blackhat

 
Posted: 27 July 2010 07:06 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

Updated to 0.9.2, fixed a couple of minor bugs :-
Full details at
http://www.matmoo.com/codeigniter/image_moo/
——————————————————————————————————————-
Any option that requires a colour can be sent as a html value,e.g. #rrggbb or as a set of values, e.g. array(rr,gg,bb)

border($width, $colour=”#000”)
Draws a frame $width pixels around the output in colour #000

border_3d($width, $rot=0, $opacity=30)
Creates a 3d border $width pixels wide around the output. Use rot 0..3 to change the highlight and lowlight position. $opacity changes the intensity of the border

filter($function, $arg1=NULL, $arg2=NULL, $arg3=NULL, $arg4=NULL)
As http://php.net/manual/en/function.imagefilter.php e.g. $this->image_moo->filter(IMG_FILTER_GRAYSCALE); to convert to greyscale

round($radius, $invert=FALSE, $corners(array(topleft, topright, bottomright, bottomleft))
Rounds the edges of the output by X pixels. Use invert to chop them out instead of rounding them. Corners is an array of 4 TRUE / FALSE values, allowing yo to control which corners get rounded.
——————————————————————————————————————-
So to create a photo effect on your image

$this->load->library('image_moo');
    
// single thumbnail
    
$this->image_moo
        
->load("myfile.x")
        ->
resize(200,200)
        ->
border(10,"#fff")           // thick white border
        
->border(1,"#000")            // thin black border
        
->save("thumb.x");
    if (
$this->image_moo->error) print $this->image_moo->display_errors(); 

So these new features allow you to make your thumbs a bit more snazzy.

Still to do :-
Fix the watermark text when angle is used
Add shadow facility
Add reflection facility *maybe*

Open to ideas of other things you might want to do in this library!

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 29 July 2010 02:21 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Joined: 2010-07-29
2 posts

Hi, this is very good library!
An idea for saving the thumbnails:
if i want to save the thumbnail like the original file name, i just write to save() that word, like thumb_marker: _thumb, in the offical image_lib smile

i hope you understand, sorry for my bad englsih smile

if i use a transparent PNG file for watermarking, why make a white background for it? :( can you help me?

 
Posted: 29 July 2010 03:19 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

Can’t see how I can add that to the current save facility easily, but easy to add it as a new function

function save_pa($prepend=""$append=""$overwrite=FALSE)
    
//----------------------------------------------------------------------------------------------------------
    // Saves the temp image as the filename specified,
    // overwrite = true of false
    //----------------------------------------------------------------------------------------------------------
    
{
        
// validate we loaded a main image
        
if (!$this->_check_image()) return $this;

        
// get current file parts
        
$parts=pathinfo($this->filename);

        
// save
        
$this->save($newfile,$parts["dirname"].'/'.$prepend.$parts['filename'].$append.$parts["extension"]);

        return 
$this;
    

Needs a new private var $filename=”” and in the load needs $this->filename=$filename;
Then (untested) you should be able $this->image_moo->load(”/a/b/c/xxx.gif”)->resize(400,400)->save_pa(“x_”,“_y”,TRUE); which would save the file as “/a/b/c/x_xxx_y.gif” at least that is the theory. Will fully test and add to library

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 26 August 2010 01:08 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

Updated to 0.9.2, fixed a couple of minor bugs :-
Full details at
http://www.matmoo.com/codeigniter/image_moo/

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
Posted: 25 September 2010 04:55 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2008-11-06
315 posts

Hello Mat-Moo,

this lib is amazing smile thank you!

Once it saved me, today I have problems using image watermarks using native CI lib. will see if your lib will help…

Btw, I could like to ask, if it could be difficult to implement smth like this:

->set_background_colour(”#49F”) - this already done
but I would need smth like this: ->set_background_image(“image.x”) - so the pic would be put over the image ....
so we have nicer background smile

Thank you so much!

 
Posted: 25 September 2010 06:57 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2008-11-06
315 posts

Hello again smile

wanted to inform you, that line 233 needs to be changed, to:

$this->save($parts["dirname"].'/'.$prepend.$parts['filename'].$append.'.'.$parts["extension"]); 

I’ll play with it and post pore results I come up with any problems, modifications:)

 
Posted: 25 September 2010 07:59 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-20
397 posts

http://www.matmoo.com/codeigniter/image_moo/ if you check the comments that has already been pointed out smile and fixed (Just not uploaded yet). What’s the point of the background image? I’m not sure what you are trying to achieve. Thanks for the positive comments though.

 Signature 

Mat-Moo
Image moo - the easy to use image library!
MatMoo.com!
E-Mail Remind - Free reminders by email
Printfetti - Your photos on confetti!

 
1 of 7
1