ๅ›พๅƒๅค„็†(ImageMagick)

็ฎ€ไป‹

่ญฆๅ‘Š

ๆญคๆ‰ฉๅฑ•ๆ˜ฏๅฎž้ชŒๆ€ง็š„ใ€‚ ๆญคๆ‰ฉๅฑ•็š„่กŒไธบ๏ผŒๅŒ…ๆ‹ฌๅ…ถๅ‡ฝๆ•ฐ็š„ๅ็งฐๅ’Œๅ›ด็ป•ๆญคๆ‰ฉๅฑ•็š„็›ธๅ…ณๆ–‡ๆกฃ้ƒฝๅฏ่ƒฝไผšๅœจๆœชๆฅ็š„ PHP ็‰ˆๆœฌไธญๅ‘็”Ÿๅ˜ๅŒ–่€Œไธๅฆ่กŒ้€š็Ÿฅใ€‚ไฝฟ็”จๆœฌๆ‰ฉๅฑ•ๅบ”่‡ช่กŒๆ‰ฟๆ‹…้ฃŽ้™ฉใ€‚

Imagick ๆ˜ฏ็”จ ImageMagic API ๆฅๅˆ›ๅปบๅ’Œไฟฎๆ”นๅ›พๅƒ็š„PHPๅฎ˜ๆ–นๆ‰ฉๅฑ•ใ€‚

ๅ…ณไบŽ ImageMagick

ImageMagick ๆ˜ฏ็”จๆฅๅˆ›ๅปบ๏ผŒ็ผ–่พ‘๏ผŒๅˆๅนถไฝๅ›พๅ›พๅƒ็š„ไธ€ๅฅ—็ป„ไปถใ€‚ ๅฎƒ่ƒฝๅคŸ็”จไบŽ่ฏปๅ–๏ผŒ่ฝฌๆข๏ผŒๅ†™ๅ…ฅๅคš็งไธๅŒๆ ผๅผ็š„ๅ›พๅƒใ€‚ ๅŒ…ๅซ DPXใ€EXRใ€GIFใ€JPEGใ€JPEG-2000ใ€PDFใ€PhotoCDใ€PNGใ€Postscriptใ€SVG ๅ’Œ TIFFใ€‚

ImageMagick Studio LLC, a non-profit organization dedicated to making software imaging solutions freely available.

๏ผ‹ๆทปๅŠ ๅค‡ๆณจ

็”จๆˆท่ดก็Œฎ็š„ๅค‡ๆณจ 3 notes

up
17
mlong-php at mlong dot us ยถ
18 years ago
Here is an example on how to take an image that is already in a string (say, from a database), and resize it, add a border, and print it out. I use this for showing reseller logos

  // Decode image from base64
  $image=base64_decode($imagedata);

  // Create Imagick object
  $im = new Imagick();

  // Convert image into Imagick
  $im->readimageblob($image);

  // Create thumbnail max of 200x82
  $im->thumbnailImage(200,82,true);

  // Add a subtle border
  $color=new ImagickPixel();
  $color->setColor("rgb(220,220,220)");
  $im->borderImage($color,1,1);

  // Output the image
  $output = $im->getimageblob();
  $outputtype = $im->getFormat();

  header("Content-type: $outputtype");
  echo $output;
up
-2
carlosvanhalen7 at gmail dot com ยถ
13 years ago
Here's a handy function that finds the first occurrence of a specific pixel. You can set the tolerance of the color you are looking for, or set it to 0 if want an exact match

<?php

function findPixel($img, $r, $g, $b, $tolerance=5)
{
    $original_                 = new Imagick($img);
    $height                    = 0;
    $width                    = 0;
    list($width, $height)    = getimagesize($img);
    $matrix_org                = array();
    $matrix_mrk                = array();

    for( $x = 0 ; $x < $width ; $x++){
        $matrix_org[$x]            = array();
        $matrix_mrk[$x]            = array();
    }

    for( $x = 0 ; $x < $width ; $x++ )
    {
        for( $y = 0 ; $y < $height ; $y++ ){
            $matrix_org[$x][$y]                = $original_->getImagePixelColor($x, $y)->getColorAsString();
            $colors                         = preg_replace('/[^-,0-9+$]/', '', $matrix_org[$x][$y]); 
            $colors                            = explode(',', $colors);
            $r_org                            = $colors[0];
            $g_org                            = $colors[1];
            $b_org                            = $colors[2];
            
            if(     ( $r <= ($r_org+$tolerance) && $r >= ($r_org - $tolerance) ) 
                &&  ( $g <= ($g_org+$tolerance) && $g >= ($g_org - $tolerance) ) 
                &&  ( $b <= ($b_org+$tolerance) && $b >= ($b_org - $tolerance) ) )
            {
                return array( $x, $y );
            }
        }
    }

    return false;
}

?>
up
-2
Eero Niemi (eero at eero dot info) ยถ
18 years ago
To load image (usually vector image, like PDF) with larger resolution than image's default is, you have to set resolution before reading the file, like this:

<?php
$im = new Imagick(); 
$im->setResolution( 300, 300 ); 
$im->readImage( "test.pdf" );
?>