Welcome Guest, Not a member yet? Register   Sign In
Image Moo - Image manipulation library
#1

[eluser]Mat-Moo[/eluser]
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 :-
Code:
$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
#2

[eluser]Mat-Moo[/eluser]
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);
#3

[eluser]Mat-Moo[/eluser]
Updated to 0.7.2 added dynamic output Smile
#4

[eluser]Laith99[/eluser]
THANKS A LOT FOR THIS LIBRARY ... IT'S SUPERLATIVE
#5

[eluser]tkyy[/eluser]
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.
#6

[eluser]Mat-Moo[/eluser]
That sounds interesting, could add it as an option to the resize_crop function (Add Tru for best guess of content location)
#7

[eluser]tkyy[/eluser]
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.
#8

[eluser]Mat-Moo[/eluser]
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!
#9

[eluser]tkyy[/eluser]
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
#10

[eluser]Mat-Moo[/eluser]
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
Code:
$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!




Theme © iAndrew 2016 - Forum software by © MyBB