Beispiel #1
0
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     try {
         $this->flot = new Flot();
         $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
         if (empty($file->error)) {
             $o_ImageProcessor = new ImageProcessor(S_BASE_PATH, S_BASE_EXTENSION . $this->flot->datastore->settings->upload_dir, $file->name);
             $o_ImageProcessor->process_and_tag_to_datastore();
         } else {
             echo $file->error;
         }
         return $file;
     } catch (Exception $e) {
         echo $e;
     }
 }
 protected static function processImageFile($inputFile, $loaderInfo)
 {
     // if no gd support, do nothing
     if (!function_exists('gd_info')) {
         return false;
     }
     // if there is only url and processMethod, do nothing
     if (count($loaderInfo) == 2) {
         return false;
     }
     // make inputFile as temprary file
     $outputFile = $inputFile;
     $processor = new ImageProcessor($inputFile);
     $transformer = new ImageTransformer($loaderInfo);
     //maintain original image type
     $imageType = null;
     $processor->transform($transformer, $imageType, $outputFile);
 }
Beispiel #3
0
 function main()
 {
     if (strtolower($_SERVER["REQUEST_METHOD"]) == "get") {
         $data = null;
         $this->view->render("tmpl_messenger", $data);
     } else {
         $IC = new ImageProcessor();
         $file_path = $IC->uploadImage();
         $response = array();
         $protect = isset($_POST["protect"]) ? $_POST["protect"] : null;
         if ($protect == 'on') {
             $signature = $_POST["signature"];
             $password = $_POST["pw"];
             $image_data = $IC->inject($file_path, $signature, $password);
             $im = imagecreatefromstring($image_data);
             imagealphablending($im, true);
             imagesavealpha($im, true);
             $file_path = $file_path . 'mod';
             imagepng($im, $file_path);
             imagedestroy($im);
         } else {
             $signature = $_POST["signature"];
             if (empty($signature)) {
                 $signature = $_POST["user_info"];
             }
             $image_data = $IC->inject($file_path, $signature);
             $im = imagecreatefromstring($image_data);
             imagealphablending($im, true);
             imagesavealpha($im, true);
             $file_path = $file_path . 'mod';
             imagepng($im, $file_path);
             imagedestroy($im);
         }
         $response["status"] = "success";
         $response["file"] = $file_path;
         echo json_encode($response);
     }
 }
Beispiel #4
0
 protected function broadcast($message)
 {
     $IC = new ImageProcessor();
     $response = array();
     $response["type"] = $message->type;
     $response["sender"] = $message->user_info;
     //접속한 모든 유저에게 메시지를 보내는 함수
     foreach ($this->CONNECTED_USR as $node) {
         if ($message->type == "msg") {
             $flag = rand(0, 2);
             switch ($flag) {
                 case 0:
                     $image_data = $IC->text2Image($message->text, $node->user_info);
                     break;
                 case 1:
                     $image_data = $IC->text2Image($message->text, $node->ip);
                     break;
                 case 2:
                     $image_data = $IC->text2Image($message->text, $node->name);
                     break;
             }
             $response["img_type_white"] = base64_encode($image_data["white"]);
             $response["img_type_yellow"] = base64_encode($image_data["yellow"]);
         } else {
             if ($message->type == "img") {
                 $flag = rand(0, 2);
                 $file_path = 'src/' . $message->file;
                 switch ($flag) {
                     case 0:
                         $image_data = $IC->watermark($file_path, $node->user_info);
                         break;
                     case 1:
                         $image_data = $IC->watermark($file_path, $node->ip);
                         break;
                     case 2:
                         $image_data = $IC->watermark($file_path, $node->name);
                         break;
                 }
                 var_dump($response);
                 $response["img"] = base64_encode($image_data);
             }
         }
         $this->send($node, json_encode($response));
     }
 }
 private function uploadFile($type, $section, $subsection, $key, $value)
 {
     $sectionData = $this->getAdminData($type, $section, $subsection);
     if (isset($value['error']) && $value['error'] != UPLOAD_ERR_OK) {
         throw new KurogoDataException(Kurogo::file_upload_error_message($value['error']));
     }
     if (!isset($value['tmp_name']) || !is_uploaded_file($value['tmp_name'])) {
         throw new KurogoDataException("Error locating uploaded file");
     }
     switch ($sectionData['sectiontype']) {
         case 'fields':
             if (!isset($sectionData['fields'][$key])) {
                 throw new KurogoConfigurationException("Invalid key {$key} for {$type} section {$section}");
             }
             $fieldData = $sectionData['fields'][$key];
             break;
         case 'section':
             $fieldData = $sectionData;
             throw new KurogoConfigurationException("Code not written for this type of field");
             break;
         default:
             throw new KurogoConfigurationException("Unable to handle {$type} {$section}. Invalid section type " . $sectionData['sectiontype']);
     }
     if (!isset($fieldData['destinationType'])) {
         throw new KurogoConfigurationException("Unable to determine destination type");
     }
     switch ($fieldData['destinationType']) {
         case 'file':
             if (!isset($fieldData['destinationFile'])) {
                 throw new KurogoConfigurationException("Unable to determine destination location");
             }
             $destination = $fieldData['destinationFile'];
             break;
         case 'folder':
             if (!isset($fieldData['destinationFile'])) {
                 throw new KurogoConfigurationException("Unable to determine destination location");
             }
             if (!isset($fieldData['destinationFolder'])) {
                 throw new KurogoConfigurationException("Unable to determine destination location");
             }
             $destination = rtrim($fieldData['destinationFolder'], '/') . '/' . ltrim($fieldData['destinationFile'], '/');
             break;
     }
     $prefix = isset($fieldData['destinationPrefix']) ? $fieldData['destinationPrefix'] : '';
     if ($prefix && defined($prefix)) {
         $destination = constant($prefix) . '/' . $destination;
     }
     if (isset($fieldData['fileType'])) {
         switch ($fieldData['fileType']) {
             case 'image':
                 $this->setResponseVersion(1);
                 try {
                     $imageData = new ImageProcessor($value['tmp_name']);
                     $transformer = new ImageTransformer($fieldData);
                     $imageType = isset($fieldData['imageType']) ? $fieldData['imageType'] : null;
                     $result = $imageData->transform($transformer, $imageType, $destination);
                     if (KurogoError::isError($result)) {
                         $this->throwError($result);
                     }
                 } catch (KurogoException $e) {
                     throw new KurogoException("Uploaded file must be a valid image (" . $e->getMessage() . ")");
                 }
                 break;
             default:
                 throw new KurogoConfigurationException("Unknown fileType " . $fieldData['fileType']);
         }
     } else {
         if (!move_uploaded_file($value['tmp_name'], $destination)) {
             $this->throwError(new KurogoError(1, "Cannot save file", "Unable to save uploaded file"));
         }
     }
 }
Beispiel #6
0
             $imageProcessor->setJpgQuality($specManager->getJpgQuality());
         }
         $imageProcessor->setUseImageMagick($specManager->getUseImageMagick());
         $imageProcessor->setWebImg($_POST['webimg']);
         $imageProcessor->setTnImg($_POST['createtnimg']);
         $imageProcessor->setLgImg($_POST['createlgimg']);
         $imageProcessor->setCreateNewRec($_POST['createnewrec']);
         $imageProcessor->setImgExists($_POST['imgexists']);
         $imageProcessor->setKeepOrig(0);
         //Run process
         $imageProcessor->batchLoadImages();
         echo '</div>' . "\n";
     }
 } elseif ($action == 'Process Output File') {
     //Process iDigBio Image ingestion appliance ouput file
     $imageProcessor = new ImageProcessor();
     echo '<ul>';
     $imageProcessor->setLogMode(3);
     $imageProcessor->setSpprid($spprid);
     $imageProcessor->setCollid($collid);
     $imageProcessor->processiDigBioOutput($specManager->getSpecKeyPattern());
     echo '</ul>';
 } elseif ($action == 'Run Batch OCR') {
     $ocrManager = new SpecProcessorOcr();
     $ocrManager->setVerbose(2);
     $batchLimit = 100;
     if (array_key_exists('batchlimit', $_POST)) {
         $batchLimit = $_POST['batchlimit'];
     }
     echo '<ul>';
     $ocrManager->batchOcrUnprocessed($collid, $procStatus, $batchLimit, 0);
 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 #8
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 #9
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();
     }
 }
// if no image
if (!file_exists($originalImagePath) || !is_file($originalImagePath)) {
    header('HTTP/1.0 404 Not Found');
    $originalImagePath = dirname(__FILE__) . '/default.png';
    $parts = array('default.png');
}
$c = count($parts);
$parts[$c - 1] = $basenamePrefix . $parts[$c - 1];
$cachedImagePath = 'cache/' . implode('/', $parts);
$cachedImageDirectory = dirname($cachedImagePath);
if (!file_exists($cachedImagePath)) {
    include_once dirname(__FILE__) . '/../../project.php';
    if (!file_exists($cachedImageDirectory)) {
        mkdir($cachedImageDirectory, 0755, true);
    }
    $imageProc = new ImageProcessor($originalImagePath);
    if (isset($method)) {
        call_user_func_array(array($imageProc, $method), $params);
    }
    if ($applyWatermark) {
        $watermarkImagePath = dirname(__FILE__) . '/watermark2.png';
        $imageProc->applyWatermark($watermarkImagePath);
    }
    $imageProc->save($cachedImagePath);
    $imageProc->destroy();
    $isCached = 'NO';
} else {
    $isCached = 'YES';
}
header('X-Image-Cached:' . $isCached);
header('Content-Type:image/jpeg');
 /**
  * @param string $imagePath - either a local absolute/relative path, or a remote URL (e.g. http://...flickr.com/.../ ). See SECURITY note above.
  * @param array $opts (
  *  curl(boolean) = false,
  *  maxCurlSize(int in Mbytes),
  *  w(pixels),
  *  h(pixels),
  *  crop(boolean) = false,
  *  scale(boolean) = true,
  *  thumbnail(boolean) = false,
  *  maxOnly(boolean) = true, # Resize only when file is larger.
  *  canvasColor(string) = '#FFFFFF',
  *  resultDir = null,
  *  remoteDir = null,
  *  outputFilename(string) = false,
  *  cacheHttpMinutes(int) = 20,
  *  overwrite(boolean) - false,
  *  onlyCreateWhenNew(boolean) - true)
  * @throws \Exception
  * @return bool|mixed|string string new URL for resized image.
  */
 public static function resize($imagePath, $opts = null)
 {
     $imagePath = urldecode($imagePath);
     # start configuration
     $resultDir = null;
     if (!empty($opts['resultDir'])) {
         $resultDir = $opts['resultDir'];
         # path to your result Dir, must be writeable by web server
         $resultDir = str_replace('/', DIRECTORY_SEPARATOR, $resultDir);
     }
     $remoteDir = null;
     if (!empty($opts['remoteDir'])) {
         $remoteDir = $opts['remoteDir'];
     }
     if (empty($remoteDir)) {
         $remoteDir = $resultDir . 'remote/';
         # path to the Dir you wish to download remote images into
     }
     $overwrite = false;
     if (isset($opts['overwrite'])) {
         $overwrite = $opts['overwrite'];
     }
     $onlyCreateWhenNew = true;
     if (isset($opts['onlyCreateWhenNew'])) {
         $onlyCreateWhenNew = $opts['onlyCreateWhenNew'];
     }
     $defaults = array('curl' => false, 'crop' => false, 'scale' => true, 'thumbnail' => false, 'maxOnly' => true, 'canvasColor' => '#FFFFFF', 'outputFilename' => false, 'resultDir' => $resultDir, 'remoteDir' => $remoteDir, 'quality' => 90, 'cacheHttpMinutes' => 20);
     $opts = array_merge($defaults, $opts);
     $path_to_convert = 'convert';
     # this could be something like /usr/bin/convert or /opt/local/share/bin/convert
     ## you shouldn't need to configure anything else beyond this point
     $purl = parse_url($imagePath);
     $finfo = pathinfo($imagePath);
     $ext_r = explode('.', $imagePath);
     $ext = $ext_r[count($ext_r) - 1];
     //if not using imagic, run the following code and return the new path immediately
     if (!empty($opts['noImagick']) && $opts['noImagick']) {
         if (file_exists($imagePath) == false) {
             $imagePath = $_SERVER['DOCUMENT_ROOT'] . $imagePath;
             if (file_exists($imagePath) == false) {
                 throw new \Exception("Image not found. (" . $imagePath . ")");
             }
         }
         $filename = md5_file($imagePath);
         if (false !== $opts['outputFilename']) {
             $opts['outputFilename'] = str_replace('/', DIRECTORY_SEPARATOR, $opts['outputFilename']);
             $newPath = $resultDir . $opts['outputFilename'];
         } else {
             $newPath = $resultDir . $filename . $ext;
         }
         if (move_uploaded_file($imagePath, $newPath)) {
             return $newPath;
         } else {
             $e = new \Exception("Unable to move the uploaded file. Please check your Dir permission.");
             throw $e;
         }
     }
     # check for remote image..
     if (isset($purl['scheme']) && ($purl['scheme'] == 'http' || $purl['scheme'] == 'https')) {
         # grab the image, and cache it so we have something to work with..
         list($filename) = explode('?', $finfo['basename']);
         $local_filepath = $remoteDir . $filename;
         $download_image = true;
         if (file_exists($local_filepath)) {
             if (filemtime($local_filepath) < strtotime('+' . $opts['cacheHttpMinutes'] . ' minutes')) {
                 $download_image = false;
             }
         }
         if ($download_image == true) {
             try {
                 if ($opts['curl'] == true) {
                     if (!empty($opts['maxCurlSize'])) {
                         if (ImageProcessor::grabSize($imagePath) <= $opts['maxCurlSize'] * 1024 * 1024) {
                             ImageProcessor::grabImage($imagePath, $local_filepath);
                         } else {
                             throw new \Exception("image too large");
                         }
                     } else {
                         ImageProcessor::grabImage($imagePath, $local_filepath);
                     }
                 }
                 $img = @file_get_contents($imagePath);
                 if (empty($img)) {
                     return "invalid image pathname";
                 } else {
                     file_put_contents($local_filepath, $img);
                 }
             } catch (\Exception $e) {
                 throw new \Exception("ERROR: While doing image resize, got this error: " . $e->getMessage());
             }
         }
         $imagePath = $local_filepath;
     }
     if (file_exists($imagePath) == false) {
         $imagePath = $_SERVER['DOCUMENT_ROOT'] . $imagePath;
         if (file_exists($imagePath) == false) {
             throw new \Exception('image not found. (' . $imagePath . ')');
         }
     }
     $w = 0;
     if (isset($opts['w'])) {
         $w = $opts['w'];
     }
     if (isset($opts['h'])) {
         $h = $opts['h'];
     }
     $filename = md5_file($imagePath);
     // If the user has requested an explicit outputFilename, do not use the cache directory.
     if (false !== $opts['outputFilename']) {
         $newPath = $resultDir . $opts['outputFilename'];
     } else {
         if (!empty($w) and !empty($h)) {
             $newPath = $resultDir . $filename . '_w' . $w . '_h' . $h . (isset($opts['crop']) && $opts['crop'] == true ? "_cp" : "") . (isset($opts['scale']) && $opts['scale'] == true ? "_sc" : "") . '.' . $ext;
         } elseif (!empty($w)) {
             $newPath = $resultDir . $filename . '_w' . $w . '.' . $ext;
         } elseif (!empty($h)) {
             $newPath = $resultDir . $filename . '_h' . $h . '.' . $ext;
         } else {
             return false;
         }
     }
     $create = true;
     if ($onlyCreateWhenNew) {
         if (file_exists($newPath) == true) {
             $create = false;
             $origFileTime = date("YmdHis", filemtime($imagePath));
             $newFileTime = date("YmdHis", filemtime($newPath));
             if ($newFileTime < $origFileTime) {
                 # Not using $opts['expire-time'] ??
                 $create = true;
             }
         }
     } else {
         if (!$overwrite) {
             if (file_exists($newPath) == true) {
                 $newExt = substr(strrchr($newPath, '.'), 1);
                 $pos = strrpos($newPath, '.' . $newExt);
                 if ($pos !== false) {
                     $noExt = substr_replace($newPath, '', $pos, strlen('.' . $newExt));
                     $count = 1;
                     while (file_exists($noExt . '-' . $count . '.' . $newExt)) {
                         $count += 1;
                     }
                     $newPath = $noExt . '-' . $count . '.' . $newExt;
                 } else {
                     $noExt = $newPath;
                     $count = 1;
                     while (file_exists($noExt . '-' . $count)) {
                         $count += 1;
                     }
                     $newPath = $noExt . '-' . $count;
                 }
             }
         }
     }
     if ($create == true) {
         if (!empty($w) and !empty($h)) {
             list($width, $height) = getimagesize($imagePath);
             if ($width > $height) {
                 $resize = $w;
                 if (true === $opts['crop']) {
                     $resize = "x" . $h;
                 }
             } else {
                 $resize = "x" . $h;
                 if (true === $opts['crop']) {
                     $resize = $w;
                 }
             }
             if (!empty($opts['imagickProgressive']) && $opts['imagickProgressive']) {
                 $progressiveCommand = "-strip -interlace Plane";
             } else {
                 $progressiveCommand = "";
             }
             if (true === $opts['scale']) {
                 $resize = $w . "x" . $h;
                 $cmd = $path_to_convert . " {$progressiveCommand} " . escapeshellarg($imagePath) . " -resize " . escapeshellarg($resize) . (true === $opts['crop'] ? "^ -background transparent -gravity center -extent " . escapeshellarg($resize) : "") . " -quality " . escapeshellarg($opts['quality']) . " " . escapeshellarg($newPath);
             } else {
                 $cmd = $path_to_convert . " {$progressiveCommand} " . escapeshellarg($imagePath) . " -resize " . escapeshellarg($resize) . " -size " . escapeshellarg($w . "x" . $h) . " xc:" . escapeshellarg($opts['canvasColor']) . " +swap -gravity center -composite -quality " . escapeshellarg($opts['quality']) . " " . escapeshellarg($newPath);
             }
         } else {
             if (self::isWindows()) {
                 $maxSign = "^>";
             } else {
                 $maxSign = "\\>";
             }
             $cmd = $path_to_convert . " " . escapeshellarg($imagePath) . " -thumbnail " . (!empty($h) ? 'x' : '') . $w . "" . (isset($opts['maxOnly']) && $opts['maxOnly'] == true ? $maxSign : "") . " -quality " . escapeshellarg($opts['quality']) . " " . escapeshellarg($newPath);
         }
         exec($cmd, $output, $return_code);
         if ($return_code == 127) {
             $path_to_convert = '/usr/local/bin/convert';
             # this could be something like /usr/bin/convert or /opt/local/share/bin/convert
             $cmd = preg_replace('/convert/', $path_to_convert, $cmd, 1);
             exec($cmd, $output, $return_code);
         }
         if ($return_code != 0) {
             throw new \Exception("Tried to execute : {$cmd}, return code: {$return_code}, output: " . print_r($output, true));
         }
     }
     # return cache file path
     return $newPath;
 }
 public function testSetIgnoredPatterns()
 {
     $patterns = array('1', '2');
     $this->processor->setIgnoredPatterns(array('1', '2'));
     $this->assertEquals($patterns, $this->processor->getIgnoredPatterns());
 }
Beispiel #13
0
 /**
  * Used to update the fields stored in a USERS row according to
  * an array holding new values
  *
  * @param array $user updated values for a USERS row
  */
 function updateUser($user)
 {
     $user_id = $user['USER_ID'];
     if (isset($user['IMAGE_STRING'])) {
         $folder = $this->getUserIconFolder($user_id);
         $image = @imagecreatefromstring($user['IMAGE_STRING']);
         $thumb_string = ImageProcessor::createThumb($image);
         file_put_contents($folder . "/user_icon.jpg", $thumb_string);
         clearstatcache($folder . "/user_icon.jpg");
     }
     unset($user['USER_ID']);
     unset($user['USER_NAME']);
     unset($user['IMAGE_STRING']);
     unset($user['USER_ICON']);
     $sql = "UPDATE USERS SET ";
     $comma = "";
     $params = array();
     if ($user == array()) {
         return;
     }
     foreach ($user as $field => $value) {
         $sql .= "{$comma} {$field}=? ";
         $comma = ",";
         if ($field == "PASSWORD") {
             $params[] = crawlCrypt($value);
         } else {
             $params[] = $value;
         }
     }
     $sql .= " WHERE USER_ID=?";
     $params[] = $user_id;
     $this->db->execute($sql, $params);
 }
             //get extension and test if acceptable
             $ext = split("\\.", $_FILES[$key]['name']);
             $ext = $ext[sizeof($ext) - 1];
             $i = $filemode == "include" && in_array($ext, $filetypes);
             if ($filemode == "include" && in_array($ext, $filetypes) || $filemode == "exclude" && !in_array($ext, $filetypes)) {
                 $news->errMsg[$key] = "Unacceptable Filetype.";
             } else {
                 if ($phpErr != 6 && $phpErr != 7) {
                     $newFileName = $path . '/' . time() . $_FILES[$key]['name'];
                     while (file_exists($newFileName)) {
                         $newFileName = $path . '/' . time() . rand(1, 99) . $_FILES[$key]['name'];
                     }
                     if (move_uploaded_file($_FILES[$key]['tmp_name'], $newFileName)) {
                         //resize photo
                         require_once './classes/imageprocessor.class.php';
                         $imageR = new ImageProcessor($newFileName, 300, $path);
                         $imageR->resizeImage();
                         //set file path to be stored in db
                         $_POST[$key] = $path . '/' . $imageR->newFileName;
                         //delete the original image
                         unlink($newFileName);
                     } else {
                         $news->errMsg[$key] = "Unable to copy file. Please try again later";
                     }
                 } else {
                     $news->errMsg[$key] = "Unable to copy file. Please try again later";
                 }
             }
         }
     }
 }
<?php

require_once '../../../config/symbini.php';
require_once $serverRoot . '/classes/ImageProcessor.php';
$imageProcessor = new ImageProcessor();
//Run process
$imageProcessor->initProcessor();
$imageProcessor->processIPlantImages();
Beispiel #16
0
 function _process_file_upload($s_upload_dir, $s_filename)
 {
     $o_ImageProcessor = new ImageProcessor(S_BASE_PATH, $s_upload_dir, $s_filename);
     $o_ImageProcessor->process_and_tag_to_datastore();
 }
Beispiel #17
0
 /**
  * Moves a file that has been uploaded via a wiki pages resource form
  * to its correct position in the resources folder so it shows up for
  * that page
  *
  * @param string $tmp_type tmp location that uploaded file initially stored
  *  at
  * @param string $file_name file name of file that has been uploaded
  * @param string $mime_type mime type of uploaded file
  * @param int $group_id group identifier of group wiki page belongs to
  * @param int $page_id identifier for page want copy a page resource for
  */
 function copyFileToGroupPageResource($tmp_name, $file_name, $mime_type, $group_id, $page_id)
 {
     $folders = $this->getGroupPageResourcesFolders($group_id, $page_id);
     if (!$folders) {
         return false;
     }
     list($folder, $thumb_folder) = $folders;
     if (move_uploaded_file($tmp_name, "{$folder}/{$file_name}")) {
         $file_string = file_get_contents("{$folder}/{$file_name}");
     } else {
         return false;
     }
     if (in_array($mime_type, array('image/png', 'image/gif', 'image/jpeg'))) {
         $image = @imagecreatefromstring($file_string);
         $thumb_string = ImageProcessor::createThumb($image);
         file_put_contents("{$thumb_folder}/{$file_name}.jpg", $thumb_string);
         clearstatcache("{$thumb_folder}/{$file_name}.jpg");
     }
     if (defined('FFMPEG') && in_array($mime_type, array('video/mp4', 'video/webm', 'video/ogg', 'video/avi', 'video/quicktime'))) {
         $make_thumb_string = FFMPEG . " -i \"{$folder}/{$file_name}\" -vframes 1 -map 0:v:0" . " -vf \"scale=" . THUMB_DIM . ":" . THUMB_DIM . "\" " . "\"{$thumb_folder}/{$file_name}.jpg\" 2>&1";
         exec($make_thumb_string);
         clearstatcache("{$thumb_folder}/{$file_name}.jpg");
     }
 }
Beispiel #18
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);
	}
Beispiel #19
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);
 }