Created
June 28, 2012 20:07
-
-
Save awartoft/3013606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$imagick = new Imagick(); | |
$imagick->readImage('image.jpeg'); | |
$it = $imagick->getPixelIterator(); | |
$width = $imagick->getImageWidth(); | |
$height = $imagick->getImageHeight(); | |
$h = 1; | |
foreach($it as $row => $pixels) | |
{ | |
$save = ($h == 1 || $h == $height); | |
$w = 1; | |
foreach($pixels as $pixel) | |
{ | |
if($width == $w || $w == 1) { | |
if ($save) { | |
$corners[] = $pixel->getColorAsString(); | |
} | |
} | |
$w++; | |
} | |
$h++; | |
} | |
$p = array_shift($corners); | |
foreach($corners as $c) { | |
if ($c != $p) { | |
die('fail not the same color'); | |
} | |
} | |
$imagick->paintTransparentImage($corners[0], 0.0, 0.0); | |
$imagick->setImageFormat('png'); | |
$imagick->writeImage('image.png'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment