Ejemplo n.º 1
1
 public function pdfAction()
 {
     $model = $this->_processSvg();
     $scale = $this->getRequest()->getPost('print_scale');
     $model->addWhiteFontForPDF();
     $data = $model->normalizeSvgData();
     if ($model->getAdditionalData('order_increment_id')) {
         $filename = 'Order_' . $model->getAdditionalData('order_increment_id') . '_Image.pdf';
     } else {
         $filename = 'Customer_Product_Image.pdf';
     }
     $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', 'application/pdf', true)->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"', true);
     $this->getResponse()->clearBody();
     //$this->getResponse()->setBody(str_replace('xlink:','',$data));
     $imagick = new Imagick();
     $imagick->readImageBlob($data);
     if ($scale != 1 && $scale <= 15) {
         $imagick->scaleImage($scale * $imagick->getImageWidth(), $scale * $imagick->getImageHeight());
     }
     $imagick->setImageFormat("pdf");
     /*$imagick->writeImage(MAGENTO_ROOT.'/media/us-map.pdf');scaleImage */
     $this->getResponse()->setBody($imagick);
     $imagick->clear();
     $imagick->destroy();
 }
Ejemplo n.º 2
1
function programmatically_create_post()
{
    $url = 'http://widgets.pinterest.com/v3/pidgets/boards/bradleyblose/my-stuff/pins/';
    $json_O = json_decode(file_get_contents($url), true);
    $id = $json_O['data']['pins'][0]['id'];
    $titlelink = 'https://www.pinterest.com/pin/' . $id . '/';
    $title = get_title($titlelink);
    var_dump($title);
    $original = $json_O['data']['pins'][0]['images']['237x']['url'];
    $image_url = preg_replace('/237x/', '736x', $original);
    $description = $json_O['data']['pins'][0]['description'];
    // Initialize the page ID to -1. This indicates no action has been taken.
    $post_id = -1;
    // Setup the author, slug, and title for the post
    $author_id = 1;
    $mytitle = get_page_by_title($title, OBJECT, 'post');
    var_dump($mytitle);
    // If the page doesn't already exist, then create it
    if (NULL == get_page_by_title($title, OBJECT, 'post')) {
        // Set the post ID so that we know the post was created successfully
        $post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_name' => $title, 'post_title' => $title, 'post_content' => $description, 'post_status' => 'publish', 'post_type' => 'post'));
        //upload featured image
        $upload_dir = wp_upload_dir();
        $image_data = file_get_contents($image_url);
        $filename = basename($image_url);
        if (wp_mkdir_p($upload_dir['path'])) {
            $file = $upload_dir['path'] . '/' . $filename;
            $path = $upload_dir['path'] . '/';
        } else {
            $file = $upload_dir['basedir'] . '/' . $filename;
            $path = $upload_dir['basedir'] . '/';
        }
        file_put_contents($file, $image_data);
        //edit featured image to correct specs to fit theme
        $pngfilename = $filename . '.png';
        $targetThumb = $path . '/' . $pngfilename;
        $img = new Imagick($file);
        $img->scaleImage(250, 250, true);
        $img->setImageBackgroundColor('None');
        $w = $img->getImageWidth();
        $h = $img->getImageHeight();
        $img->extentImage(250, 250, ($w - 250) / 2, ($h - 250) / 2);
        $img->writeImage($targetThumb);
        unlink($file);
        //Attach featured image
        $wp_filetype = wp_check_filetype($pngfilename, null);
        $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($pngfilename), 'post_content' => '', 'post_status' => 'inherit');
        $attach_id = wp_insert_attachment($attachment, $targetThumb, $post_id);
        require_once ABSPATH . 'wp-admin/includes/image.php';
        $attach_data = wp_generate_attachment_metadata($attach_id, $targetThumb);
        wp_update_attachment_metadata($attach_id, $attach_data);
        set_post_thumbnail($post_id, $attach_id);
        // Otherwise, we'll stop
    } else {
        // Arbitrarily use -2 to indicate that the page with the title already exists
        $post_id = -2;
    }
    // end if
}
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
0
 /**
  * 获取图片尺寸
  * @return array
  */
 public function getSize()
 {
     $wh = [];
     $wh['width'] = $this->image->getImageWidth();
     $wh['height'] = $this->image->getImageHeight();
     return $wh;
 }
 public function getAction($systemIdentifier, Request $request)
 {
     $width = $request->get('width');
     $height = $request->get('height');
     $system = $this->getDoctrine()->getRepository('KoalamonIncidentDashboardBundle:System')->findOneBy(['identifier' => $systemIdentifier, 'project' => $this->getProject()]);
     $webDir = $this->container->getParameter('assetic.write_to');
     if ($system->getImage() == "") {
         $imageName = $webDir . self::DEFAULT_IMAGE;
     } else {
         $imageName = $webDir . ScreenshotCommand::IMAGE_DIR . DIRECTORY_SEPARATOR . $system->getImage();
     }
     $image = new \Imagick($imageName);
     if ($height || $width) {
         if (!$height) {
             $ratio = $width / $image->getImageWidth();
             $height = $image->getImageHeight() * $ratio;
         }
         if (!$width) {
             $ratio = $height / $image->getImageHeight();
             $width = $image->getImageWidth() * $ratio;
         }
         $image->scaleImage($width, $height, true);
     }
     $headers = array('Content-Type' => 'image/png', 'Content-Disposition' => 'inline; filename="' . $imageName . '"');
     return new Response($image->getImageBlob(), 200, $headers);
 }
Ejemplo n.º 6
0
 /**
  * @param $file
  * @return string
  */
 public function thumbnail($file)
 {
     $format = '';
     $name = md5((new \DateTime())->format('c'));
     foreach ($this->sizes as $size) {
         $image = new \Imagick($file);
         $imageRatio = $image->getImageWidth() / $image->getImageHeight();
         $width = $size['width'];
         $height = $size['height'];
         $customRation = $width / $height;
         if ($customRation < $imageRatio) {
             $widthThumb = 0;
             $heightThumb = $height;
         } else {
             $widthThumb = $width;
             $heightThumb = 0;
         }
         $image->thumbnailImage($widthThumb, $heightThumb);
         $image->cropImage($width, $height, ($image->getImageWidth() - $width) / 2, ($image->getImageHeight() - $height) / 2);
         $image->setCompressionQuality(100);
         $format = strtolower($image->getImageFormat());
         $pp = $this->cachePath . '/' . $size['name'] . "_{$name}." . $format;
         $image->writeImage($pp);
     }
     return "_{$name}." . $format;
 }
Ejemplo n.º 7
0
 public static function thumbImage($imgPath, $width, $height, $blur = 1, $bestFit = 0, $cropZoom = 1)
 {
     $dir = dirname($imgPath);
     $imagick = new \Imagick(realpath($imgPath));
     if ($imagick->getImageHeight() > $imagick->getImageWidth()) {
         $w = $width;
         $h = 0;
     } else {
         $h = $height;
         $w = 0;
     }
     $imagick->resizeImage($w, $h, $imagick::DISPOSE_UNDEFINED, $blur, $bestFit);
     $cropWidth = $imagick->getImageWidth();
     $cropHeight = $imagick->getImageHeight();
     if ($cropZoom) {
         $imagick->cropImage($width, $height, ($imagick->getImageWidth() - $width) / 2, ($imagick->getImageHeight() - $height) / 2);
     }
     $direct = 'thumbs/';
     $pathToWrite = $dir . "/" . $direct;
     //var_dump($pathToWrite);
     if (!file_exists($pathToWrite)) {
         mkdir($pathToWrite, 0777, true);
     }
     $newImageName = 'thumb_' . basename($imgPath);
     //var_dump($newImageName);
     $imagick->writeImage($pathToWrite . 'thumb_' . basename($imgPath));
     return $pathToWrite . $newImageName;
 }
Ejemplo n.º 8
0
 public function draw(OsuSignature $signature)
 {
     parent::draw($signature);
     if ($this->width != -1 || $this->height != -1) {
         $this->image->resizeImage($this->width == -1 ? $this->image->getImageWidth() : $this->width, $this->height == -1 ? $this->image->getImageHeight() : $this->height, 1, $this->filter);
     }
     $signature->getCanvas()->compositeImage($this->image, $this->composite, $this->x, $this->y);
 }
Ejemplo n.º 9
0
 /**
  * @see	wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     try {
         $this->imagick->readImage($file);
     } catch (\ImagickException $e) {
         throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
     }
     $this->height = $this->imagick->getImageHeight();
     $this->width = $this->imagick->getImageWidth();
 }
Ejemplo n.º 10
0
function getSilhouette(\Imagick $imagick)
{
    $character = new \Imagick();
    $character->newPseudoImage($imagick->getImageWidth(), $imagick->getImageHeight(), "canvas:white");
    $canvas = new \Imagick();
    $canvas->newPseudoImage($imagick->getImageWidth(), $imagick->getImageHeight(), "canvas:black");
    $character->compositeimage($imagick, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
    $canvas->compositeimage($character, \Imagick::COMPOSITE_ATOP, 0, 0);
    $canvas->setFormat('png');
    return $canvas;
}
Ejemplo n.º 11
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
}
 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;
 }
Ejemplo n.º 13
0
Archivo: index.php Proyecto: hoogle/ttt
function create_thumb($source_file, $thumb_file, $edge = THUMBNAIL_CROP_EDGE, &$src_w = NULL, &$src_h = NULL)
{
    $composite_img = new Imagick($source_file);
    $blank_img = new Imagick();
    $src_w = $composite_img->getImageWidth();
    $src_h = $composite_img->getImageHeight();
    if ($src_h > $edge && $src_w > $edge) {
        $composite_img->cropThumbnailImage($edge, $edge);
        $composite_img->setImageFormat('jpeg');
        $composite_img->writeImage($thumb_file);
        $composite_img->clear();
        $blank_img = $composite_img;
    } else {
        $blank_img->newImage($edge, $edge, new ImagickPixel('#DEF'), "jpg");
        if ($src_w > $src_h) {
            $crop_x = $src_w / 2 - $edge / 2;
            $crop_y = 0;
            $offset_x = 0;
            $offset_y = $edge / 2 - $src_h / 2;
        } else {
            $crop_x = 0;
            $crop_y = $src_h / 2 - $edge / 2;
            $offset_x = $edge / 2 - $src_w / 2;
            $offset_y = 0;
        }
        $composite_img->cropImage($edge, $edge, $crop_x, $crop_y);
        $blank_img->compositeImage($composite_img, Imagick::COMPOSITE_OVER, $offset_x, $offset_y);
        $blank_img->setImageFormat('jpeg');
        $blank_img->writeImage($thumb_file);
        $blank_img->clear();
    }
    return $blank_img;
}
Ejemplo n.º 14
0
 /**
  * makeCover - For shortcuts/gallery covers
  */
 public static function makeCover($sourceImg, $destImg)
 {
     $image = new Imagick($sourceImg);
     $w_orig = $image->getImageWidth();
     $h_orig = $image->getImageHeight();
     $w_new = SmIMAGE;
     $h_new = SmIMAGE * COVERASPECT;
     $ratio_orig = $h_orig / $w_orig;
     if ($ratio_orig == COVERASPECT) {
         // Only resize
         $image->resizeImage($w_new, $h_new, Imagick::FILTER_CATROM, 1, TRUE);
     } else {
         if ($ratio_orig >= COVERASPECT) {
             // Taller than target
             $w_temp = $w_new;
             $h_temp = $w_new * $ratio_orig;
             $w_center = 0;
             $h_center = ($h_temp - $h_new) / 2;
         } else {
             // Wider than target
             $w_temp = $h_new / $ratio_orig;
             $h_temp = $h_new;
             $w_center = ($w_temp - $w_new) / 2;
             $h_center = 0;
         }
         $image->resizeImage($w_temp, $h_temp, Imagick::FILTER_CATROM, 1, TRUE);
         $image->cropImage($w_new, $h_new, $w_center, $h_center);
     }
     $image->setImageCompression(Imagick::COMPRESSION_JPEG);
     $image->setImageCompressionQuality(80);
     $image->writeImage($destImg);
     $image->destroy();
 }
Ejemplo n.º 15
0
function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom)
{
    //The blur factor where &gt; 1 is blurry, &lt; 1 is sharp.
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->resizeImage($width, $height, $filterType, $blur, $bestFit);
    $cropWidth = $imagick->getImageWidth();
    $cropHeight = $imagick->getImageHeight();
    if ($cropZoom) {
        $newWidth = $cropWidth / 2;
        $newHeight = $cropHeight / 2;
        $imagick->cropimage($newWidth, $newHeight, ($cropWidth - $newWidth) / 2, ($cropHeight - $newHeight) / 2);
        $imagick->scaleimage($imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4);
    }
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}
Ejemplo n.º 16
0
 private function _getSourceType(Imagick $image)
 {
     if ($image->getImageWidth() > 1920 && $image->getImageHeight() > 1080) {
         return Job::WQXGA;
     }
     return Job::FHD;
 }
Ejemplo n.º 17
0
 public function index()
 {
     $ps = array();
     $user = $this->session->all_userdata();
     if (isset($_POST['submit']) && isset($user) && isset($user['users_id']) && isset($_FILES['uploaded_image']['tmp_name'])) {
         $imageFile = time() . '.' . end(explode(".", $_FILES['uploaded_image']['name']));
         $photoData = $_POST['photo'];
         $image = new Imagick($_FILES['uploaded_image']['tmp_name']);
         $height = $image->getImageHeight();
         $width = $image->getImageWidth();
         if ($width > 800 || $height > 800) {
             if ($height < $width) {
                 $image->scaleImage(800, 0);
             } else {
                 $image->scaleImage(0, 600);
             }
         }
         $image->writeImage('./storage/photos/b/' . $imageFile);
         $image->cropThumbnailImage(100, 100);
         $image->writeImage('./storage/thumbs/' . $imageFile);
         $ps['photo_b'] = '/storage/photos/b/' . $imageFile;
         $ps['thumb'] = '/storage/thumbs/' . $imageFile;
         $data = array('iname' => $photoData['iname'] ? $photoData['iname'] : 'noname', 'idesc' => $photoData['idesc'] ? $photoData['idesc'] : '', 'path' => '/storage/photos/', 'file' => $imageFile, 'thumb' => $ps['thumb'], 'add_date' => time(), 'allow_comments' => isset($photoData['allow_comments']) ? 1 : 0, 'users_id' => $user['users_id']);
         $this->db->insert('photos', $data);
         $photos_id = $this->db->insert_id();
         $this->load->model('m_users');
         $this->load->model('m_logs');
         $this->m_users->update(array('num_photos' => $user['num_photos'] + 1), $user['users_id']);
         $this->m_logs->add(array('users_id' => $user['users_id'], 'action' => 1, 'object_type' => 2, 'object_id' => $photos_id));
     }
     $ps['_activeMenu'] = 'upload';
     $this->tpl->view('frontend/upload/', $ps);
 }
Ejemplo n.º 18
0
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $mimetype = $fileview->getMimeType($path);
     $path = \OC_Helper::mimetypeIcon($mimetype);
     $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
     $svgPath = substr_replace($path, 'svg', -3);
     if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
         // http://www.php.net/manual/de/imagick.setresolution.php#85284
         $svg = new \Imagick();
         $svg->readImage($svgPath);
         $res = $svg->getImageResolution();
         $x_ratio = $res['x'] / $svg->getImageWidth();
         $y_ratio = $res['y'] / $svg->getImageHeight();
         $svg->removeImage();
         $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
         $svg->setBackgroundColor(new \ImagickPixel('transparent'));
         $svg->readImage($svgPath);
         $svg->setImageFormat('png32');
         $image = new \OC_Image();
         $image->loadFromData($svg);
     } else {
         $image = new \OC_Image($path);
     }
     return $image;
 }
Ejemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function pixelate($pixelSize = 10)
 {
     $width = $this->image->getImageWidth();
     $height = $this->image->getImageHeight();
     $this->image->scaleImage((int) ($width / $pixelSize), (int) ($height / $pixelSize));
     $this->image->scaleImage($width, $height);
 }
Ejemplo n.º 20
0
 public function addWatermark($image_path)
 {
     try {
         // Open the original image
         $image = new \Imagick();
         $is_success = $image->readImage($image_path);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $watermark = new \Imagick();
         $is_success = $watermark->readImage($this->_WATERMARK_IMAGE_PATH);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $image_width = $image->getImageWidth();
         $image_height = $image->getImageHeight();
         $watermark_width = $watermark->getImageWidth();
         $watermark_height = $watermark->getImageHeight();
         $watermark_pos_x = $image_width - $watermark_width - 20;
         $watermark_pos_y = 20;
         // Overlay the watermark on the original image
         $is_success = $image->compositeImage($watermark, \imagick::COMPOSITE_OVER, $watermark_pos_x, $watermark_pos_y);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot save image after watermarked");
         }
         //Write the image
         $image->writeImage($image_path);
     } catch (ImagickException $e) {
         error_log($e->getMessage());
         throw new WatermarkException($e->getMessage(), $e->getCode(), $e);
     }
 }
Ejemplo n.º 21
0
 /**
  * @return array
  */
 public function getDimensions()
 {
     if ($vectorDimensions = $this->getVectorFormatEmbeddedRasterDimensions()) {
         return $vectorDimensions;
     }
     return ["width" => $this->resource->getImageWidth(), "height" => $this->resource->getImageHeight()];
 }
Ejemplo n.º 22
0
 function renderOriginalImage()
 {
     $imagick = new \Imagick(realpath("../imagick/images/FineDetail.png"));
     $imagick->resizeImage($imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4, \Imagick::FILTER_POINT, 1);
     \header('Content-Type: image/png');
     echo $imagick->getImageBlob();
 }
    function __construct($filename)
    {

        try {

            if(extension_loaded('imagick')) {
                $im = new Imagick();
                $im->readImage($filename);
                $width = $im->getImageWidth();
                $height = $im->getImageHeight();
                $source = new \Zxing\IMagickLuminanceSource($im, $width, $height);
            }else {
                $image = file_get_contents($filename);
                $sizes = getimagesize($filename);
                $width = $sizes[0];
                $height = $sizes[1];
                $im = imagecreatefromstring($image);

                $source = new \Zxing\GDLuminanceSource($im, $width, $height);
            }
            $histo = new Zxing\Common\HybridBinarizer($source);
            $bitmap = new Zxing\BinaryBitmap($histo);
            $reader = new Zxing\Qrcode\QRCodeReader();

            $this->result = $reader->decode($bitmap);
        }catch (\Zxing\NotFoundException $er){
            $this->result = false;
        }catch( \Zxing\FormatException $er){
            $this->result = false;
        }catch( \Zxing\ChecksumException $er){
            $this->result = false;
        }
    }
Ejemplo n.º 24
0
 /**
  * @return int
  * @throws CM_Exception
  */
 public function getHeight()
 {
     try {
         return $this->_imagick->getImageHeight();
     } catch (ImagickException $e) {
         throw new CM_Exception('Cannot detect image height: ' . $e->getMessage());
     }
 }
Ejemplo n.º 25
0
 protected function buildFitOut($params)
 {
     $newWidth = $params[0];
     $newHeight = $params[1];
     $originalWidth = $this->_image->getImageWidth();
     $originalHeight = $this->_image->getImageHeight();
     $this->_image->setGravity(!empty($params[2]) ? $params[2] : \Imagick::GRAVITY_CENTER);
     $tmpWidth = $newWidth;
     $tmpHeight = $originalHeight * ($newWidth / $originalWidth);
     if ($tmpHeight < $newHeight) {
         $tmpHeight = $newHeight;
         $tmpWidth = $originalWidth * ($newHeight / $originalHeight);
     }
     $this->_image->thumbnailImage($tmpWidth, $tmpHeight);
     $offset = self::detectGravityXY($this->_image->getGravity(), $tmpWidth, $tmpHeight, $params[0], $params[1]);
     $this->_image->cropImage($newWidth, $newHeight, $offset[0], $offset[1]);
 }
Ejemplo n.º 26
0
 /**
  * @return int
  * @throws CM_Exception
  */
 public function getHeight()
 {
     try {
         return $this->_imagick->getImageHeight();
     } catch (ImagickException $e) {
         throw new CM_Exception('Cannot detect image height', null, ['originalExceptionMessage' => $e->getMessage()]);
     }
 }
Ejemplo n.º 27
0
    /**
     * Homothetic resizement
     *
     * @param \Imagick image
     * @param integer $maxwidth
     * @param integer $maxheight
     */
    public function homothetic(\Imagick $image, $width, $height)
    {
        list($width, $height) = $this->scaleImage($image->getImageWidth(), $image->getImageHeight(), $width, $height);

        $image->thumbnailImage($width, $height);

        $image->unsharpMaskImage(0 , 0.5 , 1 , 0.05);
    }
Ejemplo n.º 28
0
 public function getOriginalImageResponse()
 {
     $imagePath = $this->getOriginalImagePath();
     $imagick = new \Imagick(realpath($imagePath));
     $imagick->resizeImage($imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4, \Imagick::FILTER_POINT, 1);
     header('Content-Type: image/png');
     echo $imagick->getImageBlob();
 }
Ejemplo n.º 29
0
 /**
  * @param int $width
  * @param int $height
  * @param int $offsetX
  * @param int $offsetY
  *
  * @return static
  */
 public function crop($width, $height, $offsetX = 0, $offsetY = 0)
 {
     $this->_image->cropImage($width, $height, $offsetX, $offsetY);
     $this->_image->setImagePage($width, $height, 0, 0);
     $this->_width = $this->_image->getImageWidth();
     $this->_height = $this->_image->getImageHeight();
     return $this;
 }
Ejemplo n.º 30
0
 /**
  * Returns the size of the Image
  *
  *
  * @param $src
  * @return mixed
  */
 public static function getImageSize($src)
 {
     $img = new Imagick($src);
     $size = new stdClass();
     $size->width = $img->getImageWidth();
     $size->height = $img->getImageHeight();
     return $size;
 }