Beispiel #1
0
	/**
	 * Renders a transparent PNG of the requested dimensions
	 *
	 * Used in the product gallery to reserve DOM dimensions so the
	 * gallery is rendered with the proper layout
	 *	 
	 * @since 1.1.7
	 *
	 * @return void Description...
	 **/
	function clearpng () {
		require_once(ECART_PATH."/core/model/Image.php");
		$max = 1920;
		$this->width = min($max,$this->width);
		$this->height = min($max,$this->height);
		$ImageData = new ImageProcessor(false,$this->width,$this->height);
		$ImageData->canvas($this->width,$this->height,true);
		$image = $ImageData->imagefile(100);
		header("Cache-Control: no-cache, must-revalidate");
		header("Content-type: image/png");
		header("Content-Disposition: inline; filename=clear.png");
		header("Content-Description: Delivered by WordPress/Ecart Image Server");
		header("Content-length: ".@strlen($image));
		die($image);
	}
 function add_images()
 {
     $QualityValue = array(100, 92, 80, 70, 60);
     $error = false;
     if (isset($_FILES['Filedata']['error'])) {
         $error = $_FILES['Filedata']['error'];
     }
     if ($error) {
         die(json_encode(array("error" => $this->uploadErrors[$error])));
     }
     require "{$this->basepath}/core/model/Image.php";
     if (isset($_POST['product'])) {
         $parent = $_POST['product'];
         $context = "product";
     }
     if (isset($_POST['category'])) {
         $parent = $_POST['category'];
         $context = "category";
     }
     // Save the source image
     $Image = new Asset();
     $Image->parent = $parent;
     $Image->context = $context;
     $Image->datatype = "image";
     $Image->name = $_FILES['Filedata']['name'];
     list($width, $height, $mimetype, $attr) = getimagesize($_FILES['Filedata']['tmp_name']);
     $Image->properties = array("width" => $width, "height" => $height, "mimetype" => image_type_to_mime_type($mimetype), "attr" => $attr);
     $Image->data = addslashes(file_get_contents($_FILES['Filedata']['tmp_name']));
     $Image->save();
     unset($Image->data);
     // Save memory for small image & thumbnail processing
     // Generate Small Size
     $SmallSettings = array();
     $SmallSettings['width'] = $this->Settings->get('gallery_small_width');
     $SmallSettings['height'] = $this->Settings->get('gallery_small_height');
     $SmallSettings['sizing'] = $this->Settings->get('gallery_small_sizing');
     $SmallSettings['quality'] = $this->Settings->get('gallery_small_quality');
     $Small = new Asset();
     $Small->parent = $Image->parent;
     $Small->context = $context;
     $Small->datatype = "small";
     $Small->src = $Image->id;
     $Small->name = "small_" . $Image->name;
     $Small->data = file_get_contents($_FILES['Filedata']['tmp_name']);
     $SmallSizing = new ImageProcessor($Small->data, $width, $height);
     switch ($SmallSettings['sizing']) {
         // case "0": $SmallSizing->scaleToWidth($SmallSettings['width']); break;
         // case "1": $SmallSizing->scaleToHeight($SmallSettings['height']); break;
         case "0":
             $SmallSizing->scaleToFit($SmallSettings['width'], $SmallSettings['height']);
             break;
         case "1":
             $SmallSizing->scaleCrop($SmallSettings['width'], $SmallSettings['height']);
             break;
     }
     $SmallSizing->UnsharpMask(75);
     $Small->data = addslashes($SmallSizing->imagefile($QualityValue[$SmallSettings['quality']]));
     $Small->properties = array();
     $Small->properties['width'] = $SmallSizing->Processed->width;
     $Small->properties['height'] = $SmallSizing->Processed->height;
     $Small->properties['mimetype'] = "image/jpeg";
     unset($SmallSizing);
     $Small->save();
     unset($Small);
     // Generate Thumbnail
     $ThumbnailSettings = array();
     $ThumbnailSettings['width'] = $this->Settings->get('gallery_thumbnail_width');
     $ThumbnailSettings['height'] = $this->Settings->get('gallery_thumbnail_height');
     $ThumbnailSettings['sizing'] = $this->Settings->get('gallery_thumbnail_sizing');
     $ThumbnailSettings['quality'] = $this->Settings->get('gallery_thumbnail_quality');
     $Thumbnail = new Asset();
     $Thumbnail->parent = $Image->parent;
     $Thumbnail->context = $context;
     $Thumbnail->datatype = "thumbnail";
     $Thumbnail->src = $Image->id;
     $Thumbnail->name = "thumbnail_" . $Image->name;
     $Thumbnail->data = file_get_contents($_FILES['Filedata']['tmp_name']);
     $ThumbnailSizing = new ImageProcessor($Thumbnail->data, $width, $height);
     switch ($ThumbnailSettings['sizing']) {
         // case "0": $ThumbnailSizing->scaleToWidth($ThumbnailSettings['width']); break;
         // case "1": $ThumbnailSizing->scaleToHeight($ThumbnailSettings['height']); break;
         case "0":
             $ThumbnailSizing->scaleToFit($ThumbnailSettings['width'], $ThumbnailSettings['height']);
             break;
         case "1":
             $ThumbnailSizing->scaleCrop($ThumbnailSettings['width'], $ThumbnailSettings['height']);
             break;
     }
     $ThumbnailSizing->UnsharpMask();
     $Thumbnail->data = addslashes($ThumbnailSizing->imagefile($QualityValue[$ThumbnailSettings['quality']]));
     $Thumbnail->properties = array();
     $Thumbnail->properties['width'] = $ThumbnailSizing->Processed->width;
     $Thumbnail->properties['height'] = $ThumbnailSizing->Processed->height;
     $Thumbnail->properties['mimetype'] = "image/jpeg";
     unset($ThumbnailSizing);
     $Thumbnail->save();
     unset($Thumbnail->data);
     echo json_encode(array("id" => $Thumbnail->id, "src" => $Thumbnail->src));
 }
Beispiel #3
0
 /**
  * Updates image details for all cached images of the product
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @param array image record ids
  * @return void
  **/
 public function update_images($images)
 {
     if (!is_array($images)) {
         return;
     }
     foreach ($images as $img) {
         $Image = new ProductImage($img['id']);
         $Image->title = stripslashes($img['title']);
         $Image->alt = stripslashes($img['alt']);
         if (!empty($img['cropping'])) {
             if (!class_exists('ImageProcessor')) {
                 require SHOPP_MODEL_PATH . "/Image.php";
             }
             foreach ($img['cropping'] as $id => $cropping) {
                 if (empty($cropping)) {
                     continue;
                 }
                 $Cropped = new ProductImage($id);
                 list($Cropped->settings['dx'], $Cropped->settings['dy'], $Cropped->settings['cropscale']) = explode(',', $cropping);
                 extract($Cropped->settings);
                 $Resized = new ImageProcessor($Image->retrieve(), $Image->width, $Image->height);
                 $scaled = $Image->scaled($width, $height, $scale);
                 $scale = ImageAsset::$defaults['scaling'][$scale];
                 $quality = $quality === false ? ImageAsset::$defaults['quality'] : $quality;
                 $Resized->scale($scaled['width'], $scaled['height'], $scale, $alpha, $fill, (int) $dx, (int) $dy, (double) $cropscale);
                 // Post sharpen
                 if ($sharpen !== false) {
                     $Resized->UnsharpMask($sharpen);
                 }
                 $Cropped->data = $Resized->imagefile($quality);
                 if (empty($Cropped->data)) {
                     return false;
                 }
                 $Cropped->size = strlen($Cropped->data);
                 if ($Cropped->store($Cropped->data) === false) {
                     return false;
                 }
                 $Cropped->save();
             }
         }
         $Image->save();
     }
 }
Beispiel #4
0
	/**
	 * update_images()
	 * Updates the image details for all cached images */
	function update_images ($images) {
		if (!is_array($images)) return false;

		foreach ($images as $img) {
			$Image = new ProductImage($img['id']);
			$Image->title = $img['title'];
			$Image->alt = $img['alt'];

			if (!empty($img['cropping'])) {
				require_once(ECART_PATH."/core/model/Image.php");

				foreach ($img['cropping'] as $id => $cropping) {
					if (empty($cropping)) continue;
					$Cropped = new ProductImage($id);

					list($Cropped->settings['dx'],
						$Cropped->settings['dy'],
						$Cropped->settings['cropscale']) = explode(',', $cropping);
					extract($Cropped->settings);

					$Resized = new ImageProcessor($Image->retrieve(),$Image->width,$Image->height);
					$scaled = $Image->scaled($width,$height,$scale);
					$scale = $Cropped->_scaling[$scale];
					$quality = ($quality === false)?$Cropped->_quality:$quality;

					$Resized->scale($scaled['width'],$scaled['height'],$scale,$alpha,$fill,(int)$dx,(int)$dy,(float)$cropscale);

					// Post sharpen
					if ($sharpen !== false) $Resized->UnsharpMask($sharpen);
					$Cropped->data = $Resized->imagefile($quality);
					if (empty($Cropped->data)) return false;

					$Cropped->size = strlen($Cropped->data);
					if ($Cropped->store( $Cropped->data ) === false)
						return false;

					$Cropped->save();

				}
			}

			$Image->save();
		}

		return true;
	}
Beispiel #5
0
 /**
  * Renders a transparent PNG of the requested dimensions
  *
  * Used in the product gallery to reserve DOM dimensions so the
  * gallery is rendered with the proper layout
  *
  * @author Jonathan Davis
  * @since 1.1.7
  *
  * @return void
  **/
 public function clearpng()
 {
     $max = 1920;
     $this->width = min($max, $this->width);
     $this->height = min($max, $this->height);
     $ImageData = new ImageProcessor(false, $this->width, $this->height);
     $ImageData->canvas($this->width, $this->height, true);
     $image = $ImageData->imagefile(100);
     $this->headers('clear.png', @strlen($image));
     ob_clean();
     // try to catch errant data in buffer
     die($image);
 }