Example #1
0
 public static function parse_list($response)
 {
     $result = array();
     $res = Text::parse_json($response);
     if (!isset($res["responseData"]["results"])) {
         throw new Exception("Invalid data");
     }
     foreach ($res["responseData"]["results"] as $re) {
         $obj = new self();
         $obj->width($re["width"]);
         $obj->height($re["height"]);
         $obj->src($re["unescapedUrl"]);
         $obj->url($re["originalContextUrl"]);
         $obj->title($re["titleNoFormatting"]);
         $obj->content($re["contentNoFormatting"]);
         $result[] = $obj;
     }
     return $result;
 }
Example #2
0
 /**
  * Do a pixel by pixel comparation of two images
  * @warning this function can take several minutes on large files
  *
  * @param mixed $image_a Path or handle to the first image
  * @param mixed $image_b Path or handle to the second image
  *
  * @return bool
  */
 public static function equal($image_a, $image_b)
 {
     if (!$image_a instanceof self) {
         $image_a = new self($image_a);
     }
     if (!$image_b instanceof self) {
         $image_b = new self($image_b);
     }
     //Compare size
     if ($image_a->width() != $image_b->width() || $image_a->height() != $image_b->height()) {
         return false;
     }
     //Compare pixel
     $ha = $image_a->handle();
     $hb = $image_b->handle();
     for ($x = 0; $x <= imagesx($ha) - 1; $x++) {
         for ($y = 0; $y <= imagesy($ha) - 1; $y++) {
             $color_a = imagecolorsforindex($ha, imagecolorat($ha, $x, $y));
             $color_b = imagecolorsforindex($hb, imagecolorat($hb, $x, $y));
             if ($color_a != $color_b) {
                 //If alfa value is zero, color doesn't matter
                 if ($color_b['alpha'] != 0 || $color_b['alpha'] != 0) {
                     return false;
                 }
             }
         }
     }
     return true;
 }