ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Image Moo - Image manipulation library

July 20, 2010 11:10am

Subscribe [38]
  • #31 / Dec 13, 2010 8:30am

    Mat-Moo

    350 posts

    I made some modifications to processing png transparency watermarks and forgot to update the text part. This is now fixed in 1.0.1 which I’ll upload to my site soon.

  • #32 / Dec 13, 2010 10:18am

    HomersBrain

    18 posts

    Thanks for the quick update. Thats working now.

    As a site note, when you specify vertical text, it’s chopping off the top part of the font. It’s to do with x co-ords of the imagefttext function.

    eg: imagefttext($this->watermark_image, $size, $angle, 0, $bh-$bl, $font_col, $fontfile, $text);

    The 0 works fine for horizontal text. If I want vertical text, I had to change the 0 to 20 (in my case) to stop it cutting the top of the text off.

    Cheers

    Mike

  • #33 / Dec 13, 2010 10:20am

    Mat-Moo

    350 posts

    In the bugs it does say not fully working with rotated text 😊 I’ll have to put some time ont hat soon 😊

  • #34 / Dec 13, 2010 11:42am

    HomersBrain

    18 posts

    In the bugs it does say not fully working with rotated text 😊

    Documentation? Who reads documentation?  :lol:

    Thanks 😊

  • #35 / Dec 13, 2010 12:08pm

    theRiley

    3 posts

    Great library it’s worked for many different things I need.

    Running into a problem with large large files… like 2000px x 3000px.  When i upload anything large like that it just goes to a blank white page.  i’ve put in the code for

    “$this->image_moo->display_errors();”

    in several different places, but still cant’ get it to print anything.  It’s all local for now, and it’s uploading the photo to the right directory, just when it gets to this part:

    if ($width >= $maxWidth || $height >= $maxHeight) {
    $this->image_moo
    ->load($filename)
    ->resize($maxWidth, $maxHeight)
    ->save($filename, $overwrite=TRUE);
    }

    It’s not changing the photo size, and goes to that white page.

    If the image is large enough to trigger this code (to go over my max width or max height) then the code DOES resize the photo and works (unless the photo is very very large).  That’s why i think it has to do with memory limits or something…

    Any ideas about large photos or memory limits?  Or even a better suggestion where i could track or see errors.

    Thanks for any help

  • #36 / Dec 13, 2010 12:13pm

    Mat-Moo

    350 posts

    Sounds like PHP running out of memory, will be a server/php setting, not a limitation of the library. But for a photo that size, your looking at around 30MB working space just to load the image in memory (2000 x 3000 x 4)

  • #37 / Dec 13, 2010 12:39pm

    theRiley

    3 posts

    Ah, yes that worked, upped my limit locally.

    Even though it wasn’t an Image Moo problem thanks for your reply

  • #38 / Dec 13, 2010 2:19pm

    mcrumley

    2 posts

    Here is a function I added to crop the image to a specific aspect ratio.

    // crop to 16x9
    $this->image_moo->load('example.jpg')->ratio(16, 9)->save_dynamic();
    public function ratio($width, $height, $rotate = false, $stretch = false)
        //----------------------------------------------------------------------------------------------------------
        // Crop the original image to the aspect ratio $width x $height
        // $rotate - keep the original image orientation even if the aspect ratio does not match
        // $stretch - stretch the image to fit instead of crop
        //----------------------------------------------------------------------------------------------------------
        {
            $ratio = $width / $height;
            $current_ratio = $this->width / $this->height;
    
            // if rotate is true and the current ratio and requested ratio are different directions
            // switch the width and height
            if ($rotate && (($ratio < 1 && $current_ratio > 1) || ($ratio > 1 && $current_ratio < 1))) {
                $ratio = $height / $width;
            }
    
            // if the current ratio is the same as the requested ratio do nothing
            if ($current_ratio == $ratio) {
                // return object
                return $this;
            }
            // if the image is wider than the requested ratio
            // use the current height and figure out the width
            if ($current_ratio > $ratio) {
                $w = $this->height * $ratio;
                $h = $this->height;
            // if the image is narrower than the requested ratio
            // use the current width and figure out the height
            } else {
                $w = $this->width;
                $h = $this->width / $ratio;
            }
    
            // stretch or crop the image
            if ($stretch) {
                $this->stretch($w, $h);
            } else {
                $this->resize_crop($w, $h);
            }
    
            // return object
            return $this;
        }
  • #39 / Jan 25, 2011 2:23am

    rockbust

    2 posts

    i can grab the code from one of my projects soon and post it for you.

    Doug, is that the code from my project you ripped me off of my $500. This money could have went to an real programmer. Never to late to fix the situation.
    http://ellislab.com/forums/viewthread/170501/#812425

  • #40 / Apr 05, 2011 6:15am

    E Hunefalk

    1 posts

    Hi,

    To start with: Thanks for a great library - it really saved me a lot of time for a project I’m working on!

    I noticed a couple of possible errors in your samples and in the library, with regards to error handling:

    -  The row if ($this->image_moo->error) print $this->image_moo->display_errors(); in your samples seems to be missing an ‘s’ at the end of $this->image_moo->error (I saw you had a couple of samples with ‘errors’ instead of ‘error’ though)[/quote]

    -  The $errors parameter in image_moo.php was never reset to FALSE once it has become TRUE - I changed in my copy to reset it in _clear_errors(). Before doing that, any loop would keep checking that parameter and return FALSE for any subsequent checks, even when there is no actual error in the current iteration.

  • #41 / Apr 05, 2011 3:26pm

    Mat-Moo

    350 posts

    Thanks for the spot on the errors 😊 Yep, probably a couple of typos, can’t spot any myself (odd!)

  • #42 / Apr 14, 2011 2:23am

    Kevin Smith

    4784 posts

    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.

  • #43 / Apr 14, 2011 5:51pm

    Atas

    45 posts

    Hello, thanks for this library!

    It would be great if i could do this:

    $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…

    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;
        }
    }
  • #44 / Apr 14, 2011 6:28pm

    web-johnny

    235 posts

    Looks very good library . I didn’t used it yet but it looks promising. It has all that I wanted.

  • #45 / Apr 27, 2011 11:33am

    Philo01

    25 posts

    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 ):

    // 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:

    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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases