Example #1
0
 /**
  * @return resource  image
  */
 public function getImage()
 {
     $url = $this->image;
     if (!function_exists("gd_info")) {
         return null;
     }
     if ($url == "") {
         return $this->createblank();
     }
     $size = $this->config()->getConfig("LIBRARIAN_IMAGE_SIZE", false, 150);
     $domains = $this->config()->getConfig("LIBRARIAN_IMAGE_DOMAINS", false);
     // images can only come from these domains, for added security
     if ($domains != null) {
         $bolPassed = Parser::withinDomain($url, $domains);
         if ($bolPassed == false) {
             throw new \Exception("librarian image not allowed from that domain");
         }
     }
     $image_string = file_get_contents($url);
     if ($image_string == "") {
         return $this->createblank();
     } else {
         // convert to a thumbnail
         $original = imagecreatefromstring($image_string);
         if ($original == false) {
             return $this->createblank();
         }
         $old_x = imagesx($original);
         $old_y = imagesy($original);
         if ($old_x > $old_y) {
             $thumb_w = $size;
             $thumb_h = $old_y * ($size / $old_x);
         }
         if ($old_x < $old_y) {
             $thumb_w = $old_x * ($size / $old_y);
             $thumb_h = $size;
         }
         if ($old_x == $old_y) {
             $thumb_w = $size;
             $thumb_h = $size;
         }
         $thumb = imagecreatetruecolor($thumb_w, $thumb_h);
         imagecopyresampled($thumb, $original, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
         imagedestroy($original);
         return $thumb;
     }
 }