public function makeSize($size) { if (!file_exists($this->file_path)) { return false; } Yii::import('lib.flourishlib.classes.*'); $original = new fImage($this->file_path); $newImage = fImage::create($this->getPathOfSize($size), $original->read()); $height = $newImage->getHeight(); $width = $newImage->getWidth(); $size = self::getSize($size); if ($height > $width) { $newImage->resize(0, $size['height']); } else { $newImage->resize($size['width'], 0); } $newImage->cropToRatio($size['width'], $size['height']); $newImage->resize($size['width'], $size['height'], true); $newImage->saveChanges(null, 100); return true; }
/** * Validates a $_FILES array against the upload configuration * * @param array $file_array The $_FILES array for a single file * @return string The validation error message */ private function validateField($file_array) { if (empty($file_array['name'])) { if ($this->required) { return self::compose('Please upload a file'); } return NULL; } if ($file_array['error'] == UPLOAD_ERR_FORM_SIZE || $file_array['error'] == UPLOAD_ERR_INI_SIZE) { $max_size = !empty($_POST['MAX_FILE_SIZE']) ? $_POST['MAX_FILE_SIZE'] : ini_get('upload_max_filesize'); $max_size = !is_numeric($max_size) ? fFilesystem::convertToBytes($max_size) : $max_size; return self::compose('The file uploaded is over the limit of %s', fFilesystem::formatFilesize($max_size)); } if ($this->max_size && $file_array['size'] > $this->max_size) { return self::compose('The file uploaded is over the limit of %s', fFilesystem::formatFilesize($this->max_size)); } if (empty($file_array['tmp_name']) || empty($file_array['size'])) { if ($this->required) { return self::compose('Please upload a file'); } return NULL; } if (!empty($this->mime_types) && file_exists($file_array['tmp_name'])) { $contents = file_get_contents($file_array['tmp_name'], FALSE, NULL, 0, 4096); if (!in_array(fFile::determineMimeType($file_array['name'], $contents), $this->mime_types)) { return self::compose($this->mime_type_message); } } if (!$this->allow_php) { $file_info = fFilesystem::getPathInfo($file_array['name']); if (in_array(strtolower($file_info['extension']), array('php', 'php4', 'php5'))) { return self::compose('The file uploaded is a PHP file, but those are not permitted'); } } if (!$this->allow_dot_files) { if (substr($file_array['name'], 0, 1) == '.') { return self::compose('The name of the uploaded file may not being with a .'); } } if ($this->image_dimensions && file_exists($file_array['tmp_name'])) { if (fImage::isImageCompatible($file_array['tmp_name'])) { list($width, $height, $other) = getimagesize($file_array['tmp_name']); if ($this->image_dimensions['min_width'] && $width < $this->image_dimensions['min_width']) { return self::compose('The uploaded image is narrower than the minimum width of %spx', $this->image_dimensions['min_width']); } if ($this->image_dimensions['min_height'] && $height < $this->image_dimensions['min_height']) { return self::compose('The uploaded image is shorter than the minimum height of %spx', $this->image_dimensions['min_height']); } if ($this->image_dimensions['max_width'] && $width > $this->image_dimensions['max_width']) { return self::compose('The uploaded image is wider than the maximum width of %spx', $this->image_dimensions['max_width']); } if ($this->image_dimensions['max_height'] && $height > $this->image_dimensions['max_height']) { return self::compose('The uploaded image is taller than the maximum height of %spx', $this->image_dimensions['max_height']); } } } if ($this->image_ratio && file_exists($file_array['tmp_name'])) { if (fImage::isImageCompatible($file_array['tmp_name'])) { list($width, $height, $other) = getimagesize($file_array['tmp_name']); if ($this->image_ratio['allow_excess_dimension'] == 'width' && $width / $height < $this->image_ratio['width'] / $this->image_ratio['height']) { return self::compose('The uploaded image is too narrow for its height. The required ratio is %1$sx%2$s or wider.', $this->image_ratio['width'], $this->image_ratio['height']); } if ($this->image_ratio['allow_excess_dimension'] == 'height' && $width / $height > $this->image_ratio['width'] / $this->image_ratio['height']) { return self::compose('The uploaded image is too short for its width. The required ratio is %1$sx%2$s or taller.', $this->image_ratio['width'], $this->image_ratio['height']); } } } }
/** * Takes a filesystem path and creates either an fDirectory, fFile or fImage object from it * * @throws fValidationException When no path was specified or the path specified does not exist * * @param string $path The path to the filesystem object * @return fDirectory|fFile|fImage */ public static function createObject($path) { if (empty($path)) { throw new fValidationException('No path was specified'); } if (!is_readable($path)) { throw new fValidationException('The path specified, %s, does not exist or is not readable', $path); } if (is_dir($path)) { return new fDirectory($path, TRUE); } if (fImage::isImageCompatible($path)) { return new fImage($path, TRUE); } return new fFile($path, TRUE); }
if (!empty($_FILES)) { $uploader = new fUpload(); $uploader->setOptional(); $uploader->setMIMETypes($acceptedFiles, 'El tipo de archivo es incorrecto'); $dir = 'uploads/banner/'; $dir2 = 'uploads/banner/thumbs/'; $imageDescrip = fRequest::encode('imageDescrip'); $uploaded = fUpload::count('files'); for ($i = 0; $i < $uploaded; $i++) { $ext = strtolower(pathinfo($_FILES['files']['name'][$i], PATHINFO_EXTENSION)); $_FILES['files']['name'][$i] = fURL::makeFriendly(str_replace(' ', '-', $_FILES['files']['name'][$i])) . ".{$ext}"; $uploader->move($dir, 'files', $i); $fileName[] = $_FILES['files']['name'][$i]; $fileType[] = $_FILES['files']['type'][$i]; copy($dir . $fileName[$i], $dir2 . $fileName[$i]); $image3 = new fImage($dir2 . $fileName[$i]); $image3->cropToRatio(1, 1, 'left', 'bottom'); $image3->resize(200, 0); $image3->saveChanges(); /* $ftp = new ftp($user,$pass); $ftp->upload($dir . "/" . $fileName[$i], 'DIR EN REMOTE'); # resize $ftp->upload($dir2 . "/" . $fileName[$i], 'DIR EN REMOTE'); $image->delete */ } /* * Add Files to DataBase (Resource) */ try {
public function tearDown() { fImage::reset(); }
/** * Saves any changes to the image * * If the file type is different than the current one, removes the current * file once the new one is created. * * This operation will be reverted by a filesystem transaction being rolled * back. If a transaction is in progress and the new image type causes a * new file to be created, the old file will not be deleted until the * transaction is committed. * * @param string $new_image_type The new file format for the image: 'NULL` (no change), `'jpg'`, `'gif'`, `'png'` * @param integer $jpeg_quality The quality setting to use for JPEG images - this may be ommitted * @param boolean $overwrite If an existing file with the same name and extension should be overwritten * @param string :$new_image_type * @param boolean :$overwrite * @return fImage The image object, to allow for method chaining */ public function saveChanges($new_image_type = NULL, $jpeg_quality = 90, $overwrite = FALSE) { // This allows ommitting the $jpeg_quality parameter, which is very useful for non-jpegs $args = func_get_args(); if (count($args) == 2 && is_bool($args[1])) { $overwrite = $args[1]; $jpeg_quality = 90; } $this->tossIfDeleted(); self::determineProcessor(); if (self::$processor == 'none') { throw new fEnvironmentException("The changes to the image can't be saved because neither the GD extension or ImageMagick appears to be installed on the server"); } $type = self::getImageType($this->file); if ($type == 'tif' && self::$processor == 'gd') { throw new fEnvironmentException('The image specified, %s, is a TIFF file and the GD extension can not handle TIFF files. Please install ImageMagick if you wish to manipulate TIFF files.', $this->file); } $valid_image_types = array('jpg', 'gif', 'png'); if ($new_image_type !== NULL && !in_array($new_image_type, $valid_image_types)) { throw new fProgrammerException('The new image type specified, %1$s, is invalid. Must be one of: %2$s.', $new_image_type, join(', ', $valid_image_types)); } if (is_numeric($jpeg_quality)) { $jpeg_quality = (int) round($jpeg_quality); } if (!is_integer($jpeg_quality) || $jpeg_quality < 1 || $jpeg_quality > 100) { throw new fProgrammerException('The JPEG quality specified, %1$s, is either not an integer, less than %2$s or greater than %3$s.', $jpeg_quality, 1, 100); } if ($new_image_type && fFilesystem::getPathInfo($this->file, 'extension') != $new_image_type) { if ($overwrite) { $path_info = fFilesystem::getPathInfo($this->file); $output_file = $path_info['dirname'] . $path_info['filename'] . '.' . $new_image_type; } else { $output_file = fFilesystem::makeUniqueName($this->file, $new_image_type); } if (file_exists($output_file)) { if (!is_writable($output_file)) { throw new fEnvironmentException('Changes to the image can not be saved because the file, %s, is not writable', $output_file); } } else { $output_dir = dirname($output_file); if (!is_writable($output_dir)) { throw new fEnvironmentException('Changes to the image can not be saved because the directory to save the new file, %s, is not writable', $output_dir); } } } else { $output_file = $this->file; if (!is_writable($output_file)) { throw new fEnvironmentException('Changes to the image can not be saved because the file, %s, is not writable', $output_file); } } // If we don't have any changes and no name change, just exit if (!$this->pending_modifications && $output_file == $this->file) { return $this; } // Wrap changes to the image into the filesystem transaction if ($output_file == $this->file && fFilesystem::isInsideTransaction()) { fFilesystem::recordWrite($this); } if (self::$processor == 'gd') { $this->processWithGD($output_file, $jpeg_quality); } elseif (self::$processor == 'imagemagick') { $this->processWithImageMagick($output_file, $jpeg_quality); } $old_file = $this->file; fFilesystem::updateFilenameMap($this->file, $output_file); // If we created a new image, delete the old one if ($output_file != $old_file) { $old_image = new fImage($old_file); $old_image->delete(); } $this->pending_modifications = array(); return $this; }
<div id="View" class = "view-frame span-23 last"> <?php if (!isset($_GET['id'])) { echo "<div class=\"ui-state-error ui-corner-all\">\r\n\t\t\t\t\t<span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 30px;\"></span>\r\n\t\t\t\t\tYou arrived to this page in error</div>"; } else { try { $inv_item = new Inv_item($_GET['id']); ?> <div id="content"> <div id="Id" class="span-8"><h1 id="idCaption"><?php echo $inv_item->prepareId(); ?> </h1> <?php try { $profile = new fImage($inv_item->getImageUrl()); if ($profile->getWidth() != 300) { $profile->resize(300, 0); $profile->saveChanges(); } echo "<img class=\"view-img\" src=\"" . $inv_item->prepareImageUrl() . "\"></img>"; } catch (fExpectedException $e) { if ($e->getMessage() === "No filename was specified") { echo "<div class=\"info\">No picture available, please upload.</div><br />"; } else { echo "<div class=\"info\">" . $e->getMessage() . "</div><br />"; } } ?> <?php if (fAuthorization::checkAuthLevel('admin')) {