/**
  * Takes samples from the given GD at 5 pixel increments
  * @param GDBackend $gd The source image
  * @param integer $horizontal Number of samples to take horizontally
  * @param integer $vertical Number of samples to take vertically
  * @return array List of colours for each sample, each given as an associative
  * array with red, blue, green, and alpha components
  */
 protected function sampleAreas(GDBackend $gd, $horizontal = 4, $vertical = 4)
 {
     $samples = array();
     for ($y = 0; $y < $vertical; $y++) {
         for ($x = 0; $x < $horizontal; $x++) {
             $colour = imagecolorat($gd->getImageResource(), $x * 5, $y * 5);
             $samples[] = ImageColorsforIndex($gd->getImageResource(), $colour);
         }
     }
     return $samples;
 }
 /**
  * Merge two Images together
  */
 public function merge(GDBackend $image)
 {
     imagealphablending($this->owner->getImageResource(), false);
     imagesavealpha($this->owner->getImageResource(), true);
     imagealphablending($image->getImageResource(), false);
     imagesavealpha($image->getImageResource(), true);
     $srcX = 0;
     $srcY = 0;
     $srcW = $image->getWidth();
     $srcH = $image->getHeight();
     $dstX = round(($this->owner->getWidth() - $srcW) / 2);
     $dstY = round(($this->owner->getHeight() - $srcH) / 2);
     $dstW = $image->getWidth();
     $dstH = $image->getHeight();
     imagecopyresampled($this->owner->getImageResource(), $image->getImageResource(), $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
     $output = clone $this->owner;
     $output->setImageResource($this->owner->getImageResource());
     return $output;
 }