Skip to content

Instantly share code, notes, and snippets.

@macnibblet
Created June 28, 2012 20:07
Show Gist options
  • Save macnibblet/3013606 to your computer and use it in GitHub Desktop.
Save macnibblet/3013606 to your computer and use it in GitHub Desktop.
<?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