示例#1
2
文件: imagen.php 项目: vlad88sv/360
function IMAGEN_tipo_normal()
{
    $escalado = 'IMG/i/m/' . $_GET['ancho'] . '_' . $_GET['alto'] . '_' . $_GET['sha1'];
    $origen = 'IMG/i/' . $_GET['sha1'];
    $ancho = $_GET['ancho'];
    $alto = $_GET['alto'];
    if (@($ancho * $alto) > 562500) {
        die('La imagen solicitada excede el límite de este servicio');
    }
    if (!file_exists($escalado)) {
        $im = new Imagick($origen);
        $im->setCompression(Imagick::COMPRESSION_JPEG);
        $im->setCompressionQuality(85);
        $im->setImageFormat('jpeg');
        $im->stripImage();
        $im->despeckleImage();
        $im->sharpenImage(0.5, 1);
        //$im->reduceNoiseImage(0);
        $im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
        $im->resizeImage($ancho, $alto, imagick::FILTER_LANCZOS, 1);
        $im->writeImage($escalado);
        $im->destroy();
    }
    $im = new Imagick($escalado);
    $output = $im->getimageblob();
    $outputtype = $im->getFormat();
    $im->destroy();
    header("Content-type: {$outputtype}");
    header("Content-length: " . filesize($escalado));
    echo $output;
}
 /**
  * @return $this
  */
 public function deInitialize()
 {
     if ($this->im instanceof \Imagick) {
         $this->im->destroy();
     }
     return $this;
 }
示例#3
0
 /**
  * Destroys allocated imagick resources
  */
 public function __destruct()
 {
     if ($this->imagick instanceof \Imagick) {
         $this->imagick->clear();
         $this->imagick->destroy();
     }
 }
 /**
  * Destructor.
  *
  * @access  public
  */
 public function __destruct()
 {
     if ($this->image instanceof Imagick) {
         $this->image->destroy();
     }
     if ($this->snapshot instanceof Imagick) {
         $this->snapshot->destroy();
     }
 }
示例#5
0
 public function save($file, $gray = false, $quality = 100)
 {
     if ($gray) {
         $this->gray();
     }
     $res = $this->image->writeImages($file, true);
     $this->image->clear();
     $this->image->destroy();
     return $res;
 }
示例#6
0
 /**
  * Adaptation the image.
  * @param int $width
  * @param int $height
  * @param int $offset_x
  * @param int $offset_y
  */
 protected function _adapt($width, $height, $offset_x, $offset_y)
 {
     $image = new \Imagick();
     $image->newImage($width, $height, 'none');
     $image->compositeImage($this->im, \Imagick::COMPOSITE_ADD, $offset_x, $offset_y);
     $this->im->clear();
     $this->im->destroy();
     $this->im = $image;
     $this->width = $image->getImageWidth();
     $this->height = $image->getImageHeight();
 }
示例#7
0
 /**
  * Creates a thumbnail with imagick.
  *
  * @param  File    $fileObject           FileObject to add properties
  * @param  string  $httpPathToMediaDir   Http path to file
  * @param  string  $pathToMediaDirectory Local path to file
  * @param  string  $fileName             Name of the image
  * @param  string  $fileExtension        Fileextension
  * @param  integer $width                Width of thumbnail, if omitted, size will be proportional to height
  * @param  integer $height               Height of thumbnail, if omitted, size will be proportional to width
  *
  * @throws ThumbnailCreationFailedException              If imagick is not supported
  * @throws InvalidArgumentException      If both, height and width are omitted or file format is not supported
  */
 private static function createThumbnailWithImagick(File &$fileObject, $httpPathToMediaDir, $pathToMediaDirectory, $fileName, $fileExtension, $width = null, $height = null)
 {
     if (!extension_loaded('imagick')) {
         throw new ExtensionNotLoadedException('Imagick is not loaded on this system');
     }
     if ($width === null && $height === null) {
         throw new InvalidArgumentException('Either width or height must be provided');
     }
     // create thumbnails with imagick
     $imagick = new \Imagick();
     if (!in_array($fileExtension, $imagick->queryFormats("*"))) {
         throw new ThumbnailCreationFailedException('No thumbnail could be created for the file format');
     }
     // read image into imagick
     $imagick->readImage(sprintf('%s/%s.%s', $pathToMediaDirectory, $fileName, $fileExtension));
     // set size
     $imagick->thumbnailImage($width, $height);
     // null values allowed
     // write image
     $imagick->writeImage(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setThumbnailLink(sprintf('%s/%sx%s-thumbnail-%s.%s', $httpPathToMediaDir, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setLocalThumbnailPath(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     // free up associated resources
     $imagick->destroy();
 }
 /**
  * @param Thumbnail $thumbnail
  * @return void
  * @throws Exception\NoThumbnailAvailableException
  */
 public function refresh(Thumbnail $thumbnail)
 {
     try {
         $filenameWithoutExtension = pathinfo($thumbnail->getOriginalAsset()->getResource()->getFilename(), PATHINFO_FILENAME);
         $temporaryLocalCopyFilename = $thumbnail->getOriginalAsset()->getResource()->createTemporaryLocalCopy();
         $documentFile = sprintf(in_array($thumbnail->getOriginalAsset()->getResource()->getFileExtension(), $this->getOption('paginableDocuments')) ? '%s[0]' : '%s', $temporaryLocalCopyFilename);
         $width = $thumbnail->getConfigurationValue('width') ?: $thumbnail->getConfigurationValue('maximumWidth');
         $height = $thumbnail->getConfigurationValue('height') ?: $thumbnail->getConfigurationValue('maximumHeight');
         $im = new \Imagick();
         $im->setResolution($this->getOption('resolution'), $this->getOption('resolution'));
         $im->readImage($documentFile);
         $im->setImageFormat('png');
         $im->setImageBackgroundColor('white');
         $im->setImageCompose(\Imagick::COMPOSITE_OVER);
         $im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_RESET);
         $im->thumbnailImage($width, $height, true);
         $im->flattenImages();
         // Replace flattenImages in imagick 3.3.0
         // @see https://pecl.php.net/package/imagick/3.3.0RC2
         // $im->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE);
         $resource = $this->resourceManager->importResourceFromContent($im->getImageBlob(), $filenameWithoutExtension . '.png');
         $im->destroy();
         $thumbnail->setResource($resource);
         $thumbnail->setWidth($width);
         $thumbnail->setHeight($height);
     } catch (\Exception $exception) {
         $filename = $thumbnail->getOriginalAsset()->getResource()->getFilename();
         $sha1 = $thumbnail->getOriginalAsset()->getResource()->getSha1();
         $message = sprintf('Unable to generate thumbnail for the given document (filename: %s, SHA1: %s)', $filename, $sha1);
         throw new Exception\NoThumbnailAvailableException($message, 1433109652, $exception);
     }
 }
示例#9
0
 public static function cropImage($dataPathRoot, $imageFileRelativeName, $imageThumbFileRelativeName, $width, $height)
 {
     $cloudStorage = CloudHelper::getCloudModule(CloudHelper::CLOUD_MODULE_STORAGE);
     $tempSrcFilePath = $cloudStorage->createTempFileForStorageFile($dataPathRoot, $imageFileRelativeName);
     $tempDestFilePath = $cloudStorage->getTempFilePath();
     //生成缩略图
     if (extension_loaded('imagick')) {
         // 如果有 imagick 模块,优先选择 imagick 模块,因为生成的图片质量更高
         $img = new \Imagick($tempSrcFilePath);
         $img->stripimage();
         //去除图片信息
         $img->setimagecompressionquality(95);
         //保证图片的压缩质量,同时大小可以接受
         $img->cropimage($width, $height, 0, 0);
         $img->writeimage($tempDestFilePath);
         $cloudStorage->moveFileToStorage($dataPathRoot, $imageThumbFileRelativeName, $tempDestFilePath);
         //主动释放资源,防止程序出错
         $img->destroy();
         unset($img);
     } else {
         // F3 框架的 Image 类限制只能操作 UI 路径中的文件,所以我们这里需要设置 UI 路径
         global $f3;
         $f3->set('UI', dirname($tempSrcFilePath));
         $img = new \Image('/' . basename($tempSrcFilePath));
         $img->resize($width, $height, true);
         $img->dump('jpeg', $tempDestFilePath);
         $cloudStorage->moveFileToStorage($dataPathRoot, $imageThumbFileRelativeName, $tempDestFilePath);
         //主动释放资源,防止程序出错
         $img->__destruct();
         unset($img);
     }
     // 删除临时文件
     @unlink($tempSrcFilePath);
     @unlink($tempDestFilePath);
 }
示例#10
0
 public function softThumb($width, $height, $path, $bg = 'transparent')
 {
     if ($this->originImage) {
         echo "\nWrite image to `{$path}`\n";
         $resizeParams = $this->getSizes($width, $height);
         $overlay = clone $this->originImage;
         $overlay->scaleImage($resizeParams['width'], $resizeParams['height']);
         $overlayGeo = $overlay->getImageGeometry();
         if ($overlayGeo['width'] > $overlayGeo['height']) {
             $resizeParams['top'] = ($height - $overlayGeo['height']) / 2;
             $resizeParams['left'] = 0;
         } else {
             $resizeParams['top'] = 0;
             $resizeParams['left'] = ($width - $overlayGeo['width']) / 2;
         }
         $thumb = new \Imagick();
         $thumb->newImage($width, $height, $bg);
         $thumb->setImageFormat("png");
         $thumb->setCompression(\Imagick::COMPRESSION_ZIP);
         $thumb->setImageCompressionQuality(0);
         $thumb->compositeImage($overlay, \Imagick::COMPOSITE_DEFAULT, $resizeParams['left'], $resizeParams['top']);
         $thumb->writeImageFile(fopen($path, "wb"));
         $thumb->destroy();
     } else {
         throw new \Exception("As first You must load image", 404);
     }
 }
示例#11
0
function alfath_svg_compiler($options)
{
    global $wp_filesystem;
    if (!class_exists('Imagick')) {
        return new WP_Error('class_not_exist', 'Your server not support imagemagick');
    }
    $im = new Imagick();
    $im->setBackgroundColor(new ImagickPixel('transparent'));
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    $file = get_template_directory() . '/assets/img/nav.svg';
    $target = get_template_directory() . '/assets/img/nav-bg.png';
    if ($wp_filesystem->exists($file)) {
        //check for existence
        $svg = $wp_filesystem->get_contents($file);
        if (!$svg) {
            return new WP_Error('reading_error', 'Error when reading file');
        }
        //return error object
        $svg = preg_replace('/fill="#([0-9a-f]{6})"/', 'fill="' . $options['secondary-color'] . '"', $svg);
        $im->readImageBlob($svg);
        $im->setImageFormat("png24");
        $im->writeImage($target);
        $im->clear();
        $im->destroy();
    } else {
        return new WP_Error('not_found', 'File not found');
    }
}
示例#12
0
文件: Thumb.php 项目: disdain/thumb
 protected function save($path)
 {
     $pathinfo = pathinfo($path);
     if (!file_exists($pathinfo['dirname'])) {
         mkdir($pathinfo['dirname'], 0777, true);
     }
     try {
         $image = new \Imagick($this->source);
         $image->thumbnailImage($this->width, $this->height, true);
         if ($this->color) {
             $thumb = $image;
             $image = new \Imagick();
             $image->newImage($this->width, $this->height, $this->color, $pathinfo['extension']);
             $size = $thumb->getImageGeometry();
             $x = ($this->width - $size['width']) / 2;
             $y = ($this->height - $size['height']) / 2;
             $image->compositeImage($thumb, \imagick::COMPOSITE_OVER, $x, $y);
             $thumb->destroy();
         }
         $image->writeImage($path);
         $image->destroy();
     } catch (\Exception $e) {
     }
     return $this;
 }
示例#13
0
文件: thumb.php 项目: Nnamso/tbox
 public function resize($file, $size = array('width' => 100, 'height' => 100), $type = 'png', $fixed = false)
 {
     $image = new Imagick($this->file);
     $image->setBackgroundColor(new ImagickPixel('transparent'));
     $image->setImageFormat($type);
     if ($fixed === true) {
         $newWidth = $size['width'];
         $newHeight = $size['height'];
     } else {
         $imageprops = $image->getImageGeometry();
         $width = $imageprops['width'];
         $height = $imageprops['height'];
         if ($width > $height) {
             $newHeight = $size['height'];
             $newWidth = $size['height'] / $height * $width;
         } else {
             $newWidth = $size['width'];
             $newHeight = $size['width'] / $width * $height;
         }
     }
     $image->resizeImage($newWidth, $newHeight, imagick::FILTER_LANCZOS, 1);
     $image->writeImage($file . '.' . $type);
     $image->clear();
     $image->destroy();
 }
示例#14
0
 public function save()
 {
     $success = parent::save();
     if ($success && isset($this->tempFile)) {
         $extension = $this->getExtension();
         //	save original
         $original = $this->name . "." . $extension;
         $path = $this->getPath(null, true);
         $this->logger->log("moving " . $this->tempFile["tmp_name"] . " to " . $path);
         $success = move_uploaded_file($this->tempFile["tmp_name"], $path);
         if ($success && $this->isImage()) {
             $thumbs = array(array('width' => 200, 'suffix' => 'small'), array('width' => 500, 'suffix' => 'med'));
             foreach ($thumbs as $thumb) {
                 $thumb_path = $this->getPath($thumb['suffix'], true);
                 $this->logger->log("thumbnailing " . $this->tempFile["tmp_name"] . " to " . $thumb_path);
                 $image = new Imagick($path);
                 $image->scaleImage($thumb['width'], 0);
                 $image->writeImage($thumb_path);
                 $image->destroy();
             }
         } else {
             if (!$success) {
                 $this->errorMessage = "Oops! We had trouble moving the file. Please try again later.";
                 $success = false;
             }
         }
     } else {
         $this->status = "Sorry, there was an error with the file: " . $this->tempFile["error"];
         $success = false;
     }
     return $success;
 }
示例#15
0
 public function destroy()
 {
     if ($this->image !== null) {
         $this->image->destroy();
         $this->image = null;
     }
 }
示例#16
0
 private function watermarkPrint_imagick($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo)
 {
     try {
         // Open the original image
         $img = new Imagick($src);
         // Open the watermark
         $watermark = new Imagick($watermark);
         // Set transparency
         if (strtoupper($watermark->getImageFormat()) !== 'PNG') {
             $watermark->setImageOpacity($transparency / 100);
         }
         // Overlay the watermark on the original image
         $img->compositeImage($watermark, imagick::COMPOSITE_OVER, $dest_x, $dest_y);
         // Set quality
         if (strtoupper($img->getImageFormat()) === 'JPEG') {
             $img->setImageCompression(imagick::COMPRESSION_JPEG);
             $img->setCompressionQuality($quality);
         }
         $result = $img->writeImage($src);
         $img->clear();
         $img->destroy();
         $watermark->clear();
         $watermark->destroy();
         return $result ? true : false;
     } catch (Exception $e) {
         return false;
     }
 }
 public function makeThumb($path, $W = NULL, $H = NULL)
 {
     $image = new Imagick();
     $image->readImage($ImgSrc);
     // Trasformo in RGB solo se e` il CMYK
     if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
         $image->transformImageColorspace(Imagick::COLORSPACE_RGB);
     }
     $image->profileImage('*', NULL);
     $image->stripImage();
     $imgWidth = $image->getImageWidth();
     $imgHeight = $image->getImageHeight();
     if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) {
         $W = $imgWidth;
         $H = $imgHeight;
     } elseif (!$H || $H == null || $H == 0) {
         $H = $W * $imgHeight / $imgWidth;
     } elseif (!$W || $W == null || $W == 0) {
         $W = $H * $imgWidth / $imgHeight;
     }
     $image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1);
     /** Scrivo l'immagine */
     $image->writeImage($path);
     /** IMAGE OUT */
     header('X-MHZ-FLY: Nice job!');
     header(sprintf('Content-type: image/%s', strtolower($image->getImageFormat())));
     echo $image->getImageBlob();
     $image->destroy();
     die;
 }
 /**
  * Destroy image handle
  *
  * @access public
  */
 function free()
 {
     if (isset($this->imagick)) {
         $this->imagick->destroy();
         $this->imagick = null;
     }
 }
示例#19
0
 /**
  * @return  void
  */
 protected function destroy()
 {
     if ($this->resource) {
         $this->resource->clear();
         $this->resource->destroy();
         $this->resource = null;
     }
 }
示例#20
0
 /**
  * Remove the current image object from memory
  */
 public function destroy()
 {
     if ($this->_checkOpenImage(false)) {
         $this->_resource->destroy();
     }
     $this->_resource = null;
     return $this;
 }
 /**
  * handler for upload requests
  */
 static function processUpload()
 {
     $config = self::getConfig();
     global $http_return_code;
     $files = array();
     if ($_SERVER["REQUEST_METHOD"] == "GET") {
         $dir = scandir($config['BASE_DIR']);
         foreach ($dir as $file_name) {
             //issue - https://github.com/veda-consulting/uk.co.vedaconsulting.mosaico/issues/28
             //Change file name to unique by adding hash so every time uploading same image it will create new image name
             $file_name = CRM_Utils_File::makeFileName($file_name);
             $file_path = $config['BASE_DIR'] . $file_name;
             if (is_file($file_path)) {
                 $size = filesize($file_path);
                 $file = ["name" => $file_name, "url" => $config['BASE_URL'] . $file_name, "size" => $size];
                 if (file_exists($config['BASE_DIR'] . $config[THUMBNAILS_DIR] . $file_name)) {
                     $file["thumbnailUrl"] = $config['BASE_URL'] . $config[THUMBNAILS_URL] . $file_name;
                 }
                 $files[] = $file;
             }
         }
     } else {
         if (!empty($_FILES)) {
             foreach ($_FILES["files"]["error"] as $key => $error) {
                 if ($error == UPLOAD_ERR_OK) {
                     $tmp_name = $_FILES["files"]["tmp_name"][$key];
                     $file_name = $_FILES["files"]["name"][$key];
                     //issue - https://github.com/veda-consulting/uk.co.vedaconsulting.mosaico/issues/28
                     //Change file name to unique by adding hash so every time uploading same image it will create new image name
                     $file_name = CRM_Utils_File::makeFileName($file_name);
                     $file_path = $config['BASE_DIR'] . $file_name;
                     if (move_uploaded_file($tmp_name, $file_path) === TRUE) {
                         $size = filesize($file_path);
                         $image = new Imagick($file_path);
                         $image->resizeImage($config[THUMBNAIL_WIDTH], $config[THUMBNAIL_HEIGHT], Imagick::FILTER_LANCZOS, 1.0, TRUE);
                         // $image->writeImage( $config['BASE_DIR'] . $config[ THUMBNAILS_DIR ] . $file_name );
                         if ($f = fopen($config['BASE_DIR'] . $config[THUMBNAILS_DIR] . $file_name, "w")) {
                             $image->writeImageFile($f);
                         }
                         $image->destroy();
                         $file = array("name" => $file_name, "url" => $config['BASE_URL'] . $file_name, "size" => $size, "thumbnailUrl" => $config['BASE_URL'] . $config[THUMBNAILS_URL] . $file_name);
                         $files[] = $file;
                     } else {
                         $http_return_code = 500;
                         return;
                     }
                 } else {
                     $http_return_code = 400;
                     return;
                 }
             }
         }
     }
     header("Content-Type: application/json; charset=utf-8");
     header("Connection: close");
     echo json_encode(array("files" => $files));
     CRM_Utils_System::civiExit();
 }
示例#22
0
 public function testImageThumbnail()
 {
     var_dump("123 Inside Image Thumbnail");
     $thumb = new \Imagick('/home/vagrant/www/consult-api/app/myimage.jpg');
     $thumb->scaleImage(200, 200, 1);
     $thumb->writeImage('/home/vagrant/www/consult-api/app/mythumb.jpg');
     $thumb->clear();
     $thumb->destroy();
 }
示例#23
0
 /**
  * Turns object into one frame Imagick object
  * by removing all frames except first
  *
  * @param  Imagick $object
  * @return Imagick
  */
 private function removeAnimation(\Imagick $object)
 {
     $imagick = new \Imagick();
     foreach ($object as $frame) {
         $imagick->addImage($frame->getImage());
         break;
     }
     $object->destroy();
     return $imagick;
 }
示例#24
0
 function createMedium($url, $filename, $width, $height)
 {
     # Function creates a smaller version of a photo when its size is bigger than a preset size
     # Excepts the following:
     # (string) $url = Path to the photo-file
     # (string) $filename = Name of the photo-file
     # (int) $width = Width of the photo
     # (int) $height = Height of the photo
     # Returns the following
     # (boolean) true = Success
     # (boolean) false = Failure
     # Set to true when creation of medium-photo failed
     global $settings;
     $error = false;
     # Size of the medium-photo
     # When changing these values,
     # also change the size detection in the front-end
     global $newWidth;
     global $newHeight;
     # Check permissions
     if (hasPermissions(LYCHEE_UPLOADS_MEDIUM) === false) {
         # Permissions are missing
         $error = true;
         echo 'Not enough persmission on the medium folder' . "\n";
     }
     # Is photo big enough?
     # Is Imagick installed and activated?
     if ($error === false && ($width > $newWidth || $height > $newHeight) && (extension_loaded('imagick') && $settings['imagick'] === '1')) {
         $newUrl = LYCHEE_UPLOADS_MEDIUM . $filename;
         # Read image
         $medium = new Imagick();
         $medium->readImage(LYCHEE . $url);
         # Adjust image
         $medium->scaleImage($newWidth, $newHeight, true);
         # Save image
         try {
             $medium->writeImage($newUrl);
         } catch (ImagickException $err) {
             Log::notice($database, __METHOD__, __LINE__, 'Could not save medium-photo: ' . $err->getMessage());
             $error = true;
             echo 'Imagick Exception:' . "\n";
             var_dump($e);
         }
         $medium->clear();
         $medium->destroy();
     } else {
         # Photo too small or
         # Imagick not installed
         $error = true;
     }
     if ($error === true) {
         return false;
     }
     return true;
 }
 public function run($file, $temp_dir)
 {
     $image = new Imagick();
     $image->readImage($file);
     $image->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
     $image->setImageResolution($this->settings['resolution'], $this->settings['resolution']);
     $image->writeImage($file);
     $image->clear();
     $image->destroy();
     return TRUE;
 }
示例#26
0
 /**
  * Создание тамбнейла:
  */
 private static function createThumbnail($path, $name)
 {
     $thumb = new Imagick($path);
     $width = $thumb->getImageWidth();
     $height = $thumb->getImageHeight();
     $s = self::scaleImage($width, $height, 150, 200);
     $thumb->scaleImage($s[0], $s[1]);
     $thumb->writeImage($name);
     $thumb->destroy();
     return true;
 }
示例#27
0
function loadDir($path)
{
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." and $file != "..") {
                //skip . and ..
                if (is_file($path . '/' . $file)) {
                    $tmpFile = trim($file);
                    $ext = pathinfo($file, PATHINFO_EXTENSION);
                    $File = pathinfo($file, PATHINFO_FILENAME);
                    $valid_exts = array('jpeg', 'JPEG', 'jpg', 'JPG', 'png', 'PNG', 'gif', 'GIF');
                    $sizes = array('f' => 45, 't' => 92, 's' => 120, 'm' => 225, 'l' => 300);
                    //required sizes in WxH ratio
                    if (in_array($ext, $valid_exts)) {
                        // if file is image then process it!
                        foreach ($sizes as $w => $h) {
                            $image = new Imagick();
                            $image->readImage($path . '/' . $tmpFile);
                            $imgWidth = $image->getImageWidth();
                            $imgHeight = $image->getImageHeight();
                            $image->resizeImage($h, $h, Imagick::FILTER_LANCZOS, 1);
                            // resize from array sizes
                            $fileName .= $File . '_' . $w . '.' . $ext;
                            //create the image filaname
                            $image->writeImage($path . '/' . $fileName);
                            $tempFileName = $path . '/' . $fileName;
                            $arrayfiles[] = $tempFileName;
                            $custWidth = $image->getImageWidth();
                            $custHeight = $image->getImageHeight();
                            echo "[ Original dimension : {$imgWidth} x {$imgHeight} ] [ Custom dimension : {$custWidth} x {$custHeight} ] Output image location: <a href='{$tempFileName}' style='text-decoration:none'> " . $tempFileName . "</a>&nbsp;&nbsp;";
                            echo "<img class='img' src='{$tempFileName}' /></br>";
                            $w = '';
                            $h = '';
                            $fileName = '';
                            $image->clear();
                            $image->destroy();
                        }
                        //end foreach sizes
                    }
                }
                if (is_dir($path . '/' . $file)) {
                    echo '</br> <div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div><span style="font-weight:bold; font-size:14px; color:red ">Directory Name: ';
                    echo $path . "/" . $file;
                    echo '</span><div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div></br>';
                    loadDir($path . '/' . $file);
                }
            }
        }
        // end while
    }
    // end handle
}
示例#28
0
文件: upload.php 项目: Ate1st/test
 public function start()
 {
     //var_dump($this->filename, $this->uploadfile);
     if (move_uploaded_file($this->tmpfilename, $this->uploadfile)) {
         $img = new Imagick($this->uploadfile);
         $img->resizeimage($this->h, $this->w, Imagick::FILTER_LANCZOS, 1);
         $img->writeimage($this->uploadfile);
         $img->destroy();
         return $this->uploaddir . $this->filenewname;
     }
     //echo 'not found';
     return false;
 }
 protected function _imageResizeAndSave($object)
 {
     $path = APPLICATION_ROOT . '/public_html/images/topcontentblock/';
     $system->lng = $this->_getParam('lng');
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($path);
     $adapter->setOptions(array('ignoreNoFile' => true));
     if (!$adapter->receive()) {
         $msgr = Sanmax_MessageStack::getInstance('SxModule_Topcontentblock_Validator');
         $msgr->addMessage('file', $adapter->getMessages(), 'title');
     }
     if ($object->getPicture() == null) {
         $object->setPicture('');
     }
     $files = $adapter->getFileInfo();
     foreach ($files as $file) {
         if (!$file['tmp_name']) {
             continue;
         }
         $path0 = $path . "253X115/";
         $path1 = $path . "1263X575/";
         $path2 = $path . "1263X325/";
         $filename = $object->createThumbName($file['name']) . '_' . time() . '.jpg';
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(253, 115);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(100);
         $image->setImageFormat('jpeg');
         $image->writeImage($path0 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(1263, 575);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setImageFormat('jpeg');
         $image->writeImage($path1 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(1263, 325);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setImageFormat('jpeg');
         $image->writeImage($path2 . $filename);
         $image->clear();
         $image->destroy();
         unlink($file['tmp_name']);
         $object->setPicture($filename);
     }
 }
 protected function _imageResizeAndSave($object)
 {
     $path = APPLICATION_ROOT . '/public_html/images/eyecatchers/';
     $system->lng = $this->_getParam('lng');
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($path);
     $adapter->setOptions(array('ignoreNoFile' => true));
     if (!$adapter->receive()) {
         $msgr = Sanmax_MessageStack::getInstance('SxModule_Eyecatchers_Validator');
         $msgr->addMessage('file', $adapter->getMessages(), 'title');
     }
     if ($object->getPicture() == null) {
         $object->setPicture('');
     }
     $files = $adapter->getFileInfo();
     foreach ($files as $file) {
         if (!$file['tmp_name']) {
             continue;
         }
         $path0 = $path . "253x115/";
         $path1 = $path . "980x450/";
         if (!is_dir($path0)) {
             mkdir($path0, 0777, true);
         }
         if (!is_dir($path1)) {
             mkdir($path1, 0777, true);
         }
         $filename = $object->createThumbName($file['name']) . '_' . time() . '.png';
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(253, 115);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(100);
         $image->setBackgroundColor(new ImagickPixel('transparent'));
         $image->setImageFormat('png32');
         $image->writeImage($path0 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(980, 450);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setBackgroundColor(new ImagickPixel('transparent'));
         $image->setImageFormat('png32');
         $image->writeImage($path1 . $filename);
         $image->clear();
         $image->destroy();
         unlink($file['tmp_name']);
         $object->setPicture($filename);
     }
 }