Beispiel #1
0
	function resize () {
		$key = (defined('SECRET_AUTH_KEY') && SECRET_AUTH_KEY != '')?SECRET_AUTH_KEY:DB_PASSWORD;
		$message = $this->Image->id.','.implode(',',$this->parameters);
		if ($this->valid != crc32($key.$message)) {
			header("HTTP/1.1 404 Not Found");
			die('');
		}

		require_once(ECART_PATH."/core/model/Image.php");
		$Resized = new ImageProcessor($this->Image->retrieve(),$this->Image->width,$this->Image->height);
		$scaled = $this->Image->scaled($this->width,$this->height,$this->scale);
		$alpha = ($this->Image->mime == "image/png");
		$Resized->scale($scaled['width'],$scaled['height'],$this->scale,$alpha,$this->fill);

		// Post sharpen
		if ($this->sharpen !== false)
			$Resized->UnsharpMask($this->sharpen);

		$ResizedImage = new ImageAsset();
		$ResizedImage->copydata($this->Image,false,array());
		$ResizedImage->name = 'cache_'.implode('_',$this->parameters);
		$ResizedImage->filename = $ResizedImage->name.'_'.$ResizedImage->filename;
		$ResizedImage->parent = $this->Image->id;
		$ResizedImage->context = 'image';
		$ResizedImage->mime = "image/jpeg";
		$ResizedImage->id = false;
		$ResizedImage->width = $Resized->width;
		$ResizedImage->height = $Resized->height;
		foreach ($this->args as $index => $arg)
			$ResizedImage->settings[$arg] = isset($this->parameters[$index])?intval($this->parameters[$index]):false;

		$ResizedImage->data = $Resized->imagefile($this->quality);
		if (empty($ResizedImage->data)) return false;

		$ResizedImage->size = strlen($ResizedImage->data);
		$this->Image = $ResizedImage;
		if ($ResizedImage->store( $ResizedImage->data ) === false)
			return false;

		$ResizedImage->save();

	}
Beispiel #2
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;
	}
 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 #4
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();
     }
 }