Beispiel #1
0
  public function border($attr) {

    global $wf;
    $ic = $wf->get_image_class();
    
    $r = wp_parse_args( $attr, array( 
      "width" => 1,       //  border width
      "mode" => "o",      //  mode - i (inset, same size, original image will shrink inside border), or o (outset, image size will increase for border) 
      "color" => "FFF"   //  gap between image and reflection
    ));

    $color = $r["color"];
    $color_hex = $r["color"];
    
    if (!is_array($color)) {
      $color = WOOF::hex_to_rgb($color);
    } else {
      $color_hex = WOOF::rgb_to_hex($color);
    }
    
    if (isset($r["w"])) {
      $r["width"] = $r["w"];
    }
  
    $r["suffix"] = ".border.".str_replace("#", "", $color_hex).$r["mode"].$r["width"];
  
    $ci = $this->cacheinfo($r);
    
    if (file_exists($ci["path"]) && !isset($r["nocache"])) {
      return new $ic( $ci["path"], $ci["url"], $this->attr() );
    } else {
      
      $image = WOOF_Image::load($this->filepath());
      
      if ($r["mode"] == "o") {
        $output_height = $this->height() + ($r["width"] * 2);    //    calculate height of output image
        $output_width = $this->width() + ($r["width"] * 2);    //    calculate height of output image
      } else {
        $output_height = $this->height();
        $output_width = $this->width();  
      }
      
      $out = imagecreatetruecolor($output_width, $output_height);
      imagealphablending($out, false);
      $bg = imagecolorallocate($out, $color[0], $color[1], $color[2]);
      
      imagefill($out, 0, 0, $bg);
      
      if ($r["mode"] == "o") {
        imagecopyresized($out, $image, $r["width"], $r["width"], 0, 0, $this->width(), $this->height(), $this->width(), $this->height());
      } else {
        imagecopyresized($out, $image, $r["width"], $r["width"], 0, 0, $this->width() - ($r["width"] * 2), $this->height() - ($r["width"] * 2), $this->width(), $this->height());
      }

      if ( self::save_image( $ci["path"], $out, $this->infer_content_type($r) ) ) {
        return new $ic( $ci["path"], $ci["url"], $this->attr() );
      }
      
    }

    
  }