PHP Imagemagick class

This PHP Class makes it possible to process images in a very easy way.

Current functionality:

  • retrieve image data
  • flip
  • dither
  • monochrome
  • negate
  • rotate
  • blur
  • draw frame
  • resize
  • square
  • crop
  • convert
  • save

To scale an image to 640x480 when it's bigger just do this:

include('imagemagick.class.php');
$im = new Imagemagick($targetdir);
$im->Resize(640, 480, 'keep_aspect');
$im->Save();
$im->CleanUp();
?>

Download here: imagemagickclass.tar.gz

You can also find this project on http://www.freshmeat.net

Support

You can support one or more projects by donating a small or big amount of cash to my PayPal account. Please don’t forget to mention the project you’re donating to, so I can mention you in the credits!

Donate

15 Comments »

15 Responses to “PHP Imagemagick class”

  1. ayan on 22 Dec 2006 at 6:12 pm #

    i am trying to download the imagemagick class but can’t find a link anywhere.

  2. daniel on 30 Dec 2006 at 6:54 pm #

    Oops forgot to place the file :) Just placed it.

  3. bjou on 09 Jan 2007 at 9:43 pm #

    just wanted to say thanks, made my work a lot easier!

  4. flicknut on 24 Jan 2007 at 1:57 am #

    Hey nice class! I just have one problem. When attempting to crop a 1024×768 jpeg file, it ignores the Y-size and Method.

    It always crops from the left and only crops to the X-size. For some reason I don\’t have this problem with smaller files.

    You can test it here:
    http://www.flickvine.com/lib/imagemagick/index.php

    I am running ImageMagick 6.3.2

  5. Cícero Moraes on 06 Mar 2007 at 3:41 am #

    Hi there!

    Congratulations for the class, this i’ll be many usefull for a friend project that I’m helping.

    A big hug and sucess!

  6. Raam on 06 Oct 2007 at 7:54 pm #

    I used this in an email-photo-upload application I\’m in the process of creating. When I release it, it will be called phpEmail2Photo, so try Googling for it in a few weeks.

    Great stuff! Thanks!

  7. flicknut on 18 Dec 2007 at 1:09 pm #

    Does anyone know if this script works with Windows and WAMP? I\’m trying to use it (albeit unsucessfully) on my test server.

  8. Antonio on 09 Jan 2008 at 11:18 am #

    Hi, I\’m triyin to use this script in windows, but I think that not works, pliz, why don\’t rewrite the folders configration to work with windows too?, thanks

  9. Huw on 26 May 2008 at 5:55 pm #

    Hi. Great class. Thanks :-)

    I’m trying to add an automatic thumbnail generator to the class but I seem to be failing. Can anyone help?

    I hacked this from parts of the other classes …

    function ResizeTN(120, 90, $how=’fit’) {

    $method = $how==’keep_aspect’?'>’:($how==’fit’?'!’:”);
    $command = “{$this->imagemagickdir}/convert -geometry ‘{$x_size}x{$y_size}{$method}’ ‘{$this->temp_dir}/tmp{$this->count}_{$this->temp_file}’ ‘{$this->temp_dir}/tmp”.++$this->count.”_{$this->temp_file}’”;

    exec($command, $returnarray, $returnvalue);
    } else {
    $this->file_history[] = $this->temp_dir.’/tmp’.$this->count.’_’.$this->temp_file;
    }
    }
    if(!@copy($this->temp_dir.’/tmp’.$this->count.’_’.$this->temp_file, $this->tndir.’/’.$prefix.$this->temp_file)) {
    $this->error .= “ImageMagick: Couldn’t save to {$this->targetdir}/’{$prefix}{$this->temp_file}\n”;
    } else {
    }
    return $prefix.$this->temp_file;
    }

    Can someone tell me where I’m going wrong with this?

    TIA

    Huw

  10. Hamlet on 18 Aug 2008 at 8:08 pm #

    Here is example how to add Drow Text function in “imagemagickclass” Class

    function DrowText($text_text,$text_x,$text_y,$pointsize=null,$fill=null) {
    $command = $this->imagemagickdir.”/convert “;
    if($pointsize) {
    $command .= “-pointsize {$pointsize} -font C:\\WINDOWS\\Fonts\\Acidic.ttf”;
    }
    if($fill) {
    $command .= ” -fill {$fill}”;
    }
    $command .= ” -annotate 0×0+{$text_x}+{$text_y} \”{$text_text}\” {$this->temp_dir}/tmp{$this->count}_{$this->temp_file} {$this->temp_dir}/tmp”.++$this->count.”_{$this->temp_file}”;
    exec($command, $returnarray, $returnvalue);
    if($this->verbose == TRUE) {
    echo ” Command: {$command}\n”;
    }
    if($returnvalue) {
    die(“ImageMagick: Annotate Failed”);
    } else {
    $this->file_history[] = $this->temp_dir.’/tmp’.$this->count.’_’.$this->temp_file;
    }
    }

  11. Th in Colorado on 04 Nov 2008 at 8:35 pm #

    I’m getting the error Imagemagick: Upload failed right at the start. The temp directory is writeable. What am I doing wrong?

  12. Sillysoft on 20 Jan 2009 at 10:40 pm #

    If you are trying to crop an image and it ignores the Y size then all you have to do in the class file under the crop function change line 469:

    if($size_y > $this->size[1]) {

    To this:

    if($size_y > intval($this->size[1])) {

  13. Joan on 25 May 2010 at 7:49 pm #

    I am sending an image from Flash to the imagebrick script and I want to create 4 new images (with different sizes). Right now it only works the first one… it seems that the image from Flash gets lost. Any idea how to fix this?

    Resize(90,90, ‘keep_aspect’);
    $thumb -> SaveArchivo($uploadThumb);
    $thumb -> CleanUp();

    $detalle = new ImageMagick($_FILES['Filedata']);
    $detalle -> Resize(280,280, ‘keep_aspect’);
    $detalle -> SaveArchivo($uploadFile);
    $detalle -> CleanUp();

    $portada = new ImageMagick($_FILES['Filedata']);
    $portada -> Resize(640,640, ‘keep_aspect’);
    $portada -> SaveArchivo($uploadPortada);
    $portada -> CleanUp();

    $grande = new ImageMagick($_FILES['Filedata']);
    $grande -> Resize($_GET["size"],$_GET["size"], ‘keep_aspect’);
    $grande -> SaveArchivo($uploadGrande);
    $grande -> CleanUp();

    echo “uploaded”;

    ?>

  14. Joan on 25 May 2010 at 7:50 pm #

    Sorry, my previous post got cut…

    I am sending an image from Flash to the imagebrick script and I want to create 4 new images (with different sizes). Right now it only works the first one… it seems that the image from Flash gets lost. Any idea how to fix this?

    Resize(90,90, ‘keep_aspect’);
    $thumb -> SaveArchivo($uploadThumb);
    $thumb -> CleanUp();

    $detalle = new ImageMagick($_FILES['Filedata']);
    $detalle -> Resize(280,280, ‘keep_aspect’);
    $detalle -> SaveArchivo($uploadFile);
    $detalle -> CleanUp();

    $portada = new ImageMagick($_FILES['Filedata']);
    $portada -> Resize(640,640, ‘keep_aspect’);
    $portada -> SaveArchivo($uploadPortada);
    $portada -> CleanUp();

    $grande = new ImageMagick($_FILES['Filedata']);
    $grande -> Resize($_GET["size"],$_GET["size"], ‘keep_aspect’);
    $grande -> SaveArchivo($uploadGrande);
    $grande -> CleanUp();

    echo “uploaded”;

    ?>

  15. Janki on 10 Oct 2011 at 6:08 am #

    Hello,

    I want to download imagemgic class, but the file is corrupted.. can you please provide me the imagemagic.class.php.

    Please do needful.

    Thanks and Regards..

Trackback URI | Comments RSS

Leave a Reply


+ 4 = six