0

일부 명령 행 imagick 코드를 PHP 클래스로 변환해야합니다. 우리 프로덕션 박스에서 커맨드 라인 스크립트를 실행할 수 없기 때문에 클래스를 사용할 수 있어야합니다. 불행하게도이 둘 사이의 변환에 대한 문서는 없습니다.PHP GD 또는 Imagick 클래스 이미지 Magick 변환

누구나 imagick 클래스를 사용하여이 작업을 수행 할 수있는 방법을 알고 있습니까?

$color_mask ="convert -size $dimensions xc:#$color -fill white"; 

/* create the silver mask */ 
$silver_mask ="convert -size $dimensions xc:#e6e7e8 -fill white"; 

/* resize the image to the $larger_dim before cropping it to the dimensions to get that "zoomed in" effect */ 
$thumb = "convert images/$im -thumbnail $larger_dim^ ". 
" -gravity center -extent $dimensions PNG:-"; 

/* screen the resized thumbnail and the color mask */ 
$masked = "convert $thumb $color_mask -compose Screen -gravity center -composite PNG:-"; 

/* multiply the masked thumb with the silver mask */ 
$final = "convert $masked $silver_mask -compose Multiply -gravity center -composite PNG:-"; 

/* Output the image*/ 
header("Content-Type: image/png"); 
passthru($final, $retval); 

내가 대신 GD에 동일한 작업을 수행 드리겠습니다, 난 그냥 GD의 품질 권리를 얻는 문제를 했어.

TIA

답변

2

확인,이 php.net의 문서로 파악 꽤 걸렸다은 크지하며 ImageMagick이 명령 라인과 기능의 사이에 해당하는 기능을 설명하는 어느 곳이 없다 Imagick PHP 클래스.

여기 위를 수행하는 제 기능입니다 :

public static function getColorImg($img, $color, $filename) { 

if (class_exists('Imagick')) { 

    // Create the blue overlay 
    $blue = new Imagick(); 

    // Create a plain colour image in the selected color 
    $blue->newImage($dimensions['width'], $dimensions['height'], new ImagickPixel($color)); 
    $blue->setImageFormat('png'); 

    // Create the plain grey image 
    $grey = new Imagick(); 
    $grey->newImage($dimensions['width'], $dimensions['height'], new ImagickPixel($silver)); 
    $grey->setImageFormat('png'); 

    // Now grab the actual image and change it's size to the larger image 
    $image = new Imagick($img); 
    $image->setImageFormat('png'); 
    $image->thumbnailImage($larger_dim['width'], $larger_dim['height'], TRUE); 
    // now zoom it in 
    $image->cropThumbnailImage($dimensions['width'], $dimensions['height']); 
    // Screen takes multiple commands in the php class. Negate the two images 
    $image->negateImage(false); 
    $blue->negateImage(false); 
    // Then multipy them. 
    $image->compositeImage($blue, imagick::COMPOSITE_MULTIPLY, 0, 0); 
    // Re nagate the image so that it looks back to normal. 
    $image->negateImage(false); 
    // Now multiply it with the silver image 
    $image->compositeImage($grey, imagick::COMPOSITE_MULTIPLY, 0, 0); 
    // Write out the file as original file name with the prefix 
    if ($image->writeImage($filename)) { 
    $return = $filename; 
    } 
    else { 
    $return = FALSE; 
    } 
} 
else { 
    $return = FALSE; 
} 

return $return; 
}