示例#1
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;
 }
示例#2
0
 /**
  * @param $fileArray
  * @param bool $create_thumb
  * @param $destination // relative to app/public/files directory, no trailing slash
  * @return bool|string
  */
 public function saveImage($fileArray, $create_thumb = false, $destination = false)
 {
     $tmp_file = $fileArray['tmp_name'];
     $name = $fileArray['name'];
     if (!$destination) {
         $dest = $this->dest;
     } else {
         $dest = $this->dest . DS . $destination;
     }
     $img = new \Imagick($tmp_file);
     $img_width = $img->getimagewidth();
     $img_height = $img->getimageheight();
     if ($this->_height == 'auto' && is_numeric($this->_width) && $img_width > $this->_width) {
         // resize only width
         $img->resizeimage($img_width, 0, \Imagick::FILTER_LANCZOS, 1);
     } elseif ($this->_width == 'auto' && is_numeric($this->_height) && $img_height > $this->_height) {
         $img->resizeimage(0, $img_height, \Imagick::FILTER_LANCZOS, 1);
     } elseif (is_numeric($this->_height) && is_numeric($this->_width)) {
         $img->resizeimage($img_width, $img_height, \Imagick::FILTER_LANCZOS, 1, 1);
     }
     #dpi
     $img->setImageUnits(\Imagick::RESOLUTION_PIXELSPERINCH);
     $img->setImageResolution($this->_dpi, $this->_dpi);
     #compression
     $img->setImageCompressionQuality($this->_compression);
     $name = substr(md5(microtime()), 0, 4) . $name;
     $name = str_replace(' ', '', $name);
     try {
         $img->writeimage($dest . DS . $name);
     } catch (\Exception $e) {
         return false;
     }
     if ($create_thumb) {
         $this->createThumb($tmp_file, $dest . DS . 'thumb_' . $name, $this->_thumb_width, $this->_thumb_height);
     }
     return $name;
 }
示例#3
0
function fxAnalyzeImage(\Imagick $imagick)
{
    $graphWidth = $imagick->getImageWidth();
    $sampleHeight = 20;
    $graphHeight = 128;
    $border = 2;
    $imageIterator = new \ImagickPixelIterator($imagick);
    $reds = [];
    foreach ($imageIterator as $pixels) {
        /* Loop through pixel rows */
        foreach ($pixels as $pixel) {
            /* Loop through the pixels in the row (columns) */
            /** @var $pixel \ImagickPixel */
            $color = $pixel->getColor();
            $reds[] = $color['r'];
        }
        $imageIterator->syncIterator();
        /* Sync the iterator, this is important to do on each iteration */
    }
    $draw = new \ImagickDraw();
    $strokeColor = new \ImagickPixel('red');
    $fillColor = new \ImagickPixel('none');
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);
    $draw->setStrokeWidth(1);
    $draw->setFontSize(72);
    $draw->setStrokeAntiAlias(true);
    $x = 0;
    $points = [];
    foreach ($reds as $red) {
        $pos = $graphHeight - $red * $graphHeight / 256;
        $points[] = ['x' => $x, 'y' => $pos];
        $x += 1;
    }
    $draw->polyline($points);
    $plot = new \Imagick();
    $plot->newImage($graphWidth, $graphHeight, 'white');
    $plot->drawImage($draw);
    $outputImage = new \Imagick();
    $outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
    $outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
    $imagick->resizeimage($imagick->getImageWidth(), $sampleHeight, \Imagick::FILTER_LANCZOS, 1);
    $outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
    $outputImage->borderimage('black', $border, $border);
    $outputImage->setImageFormat("png");
    header("Content-Type: image/png");
    echo $outputImage;
}
示例#4
0
文件: drawer.php 项目: n0rp3d/klever
 public function makePreview($pdf_path, $preview_path)
 {
     $im = new Imagick();
     $im->setResolution(300, 300);
     $im->readimage($pdf_path . '[0]');
     $im->setImageFormat('jpeg');
     $im->resizeimage(538, 360, Imagick::FILTER_LANCZOS, 1);
     $im->writeImage($preview_path);
     $im->clear();
     $im->destroy();
 }
示例#5
0
文件: admin.php 项目: n0rp3d/klever
 public function save_design()
 {
     if ($this->input->post('mode') == 'edit') {
         $this->db->delete('designs', array('id' => $this->input->post('design_id')));
     }
     $faceMacket = str_replace('http://klever.media/', '', $this->input->post('faceMacket'));
     $backMacket = str_replace('http://klever.media/', '', $this->input->post('backMacket'));
     $face = $this->input->post('face');
     $back = $this->input->post('back');
     // get all fonts
     $query = $this->db->get('fonts');
     $fonts = array();
     foreach ($query->result() as $font) {
         $fonts[$font->family] = $font->source;
     }
     // generate pdf face template name and preview name
     $face_pdf = 'uploads/redactor/face_' . md5(microtime(true)) . '.pdf';
     $face_preview = 'uploads/redactor/face_' . md5(microtime(true)) . '.jpg';
     // convert face image to pdf
     $img = new Imagick($faceMacket);
     $img->setresolution(300, 300);
     $img->setcolorspace(Imagick::COLORSPACE_CMYK);
     $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
     $img->setimageformat('pdf');
     $img->writeimage($face_pdf);
     // include TCPDF ana FPDI
     include_once APPPATH . 'libraries/tcpdf/tcpdf.php';
     include_once APPPATH . 'libraries/tcpdf/fpdi.php';
     include_once APPPATH . 'libraries/tcpdf/include/tcpdf_fonts.php';
     $fontMaker = new TCPDF_FONTS();
     // создаём лист
     $pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
     $pdf->SetMargins(0, 0, 0, true);
     $pdf->AddPage('L');
     // загрузим ранее сохранённый шаблон
     $pdf->setSourceFile($face_pdf);
     $pdf->SetMargins(0, 0, 0, true);
     $tplIdx = $pdf->importPage(1);
     $pdf->useTemplate($tplIdx, null, null, 0, 0, true);
     // установим опции для pdf
     $pdf->setCellHeightRatio(1);
     $pdf->setCellPaddings(0, 0, 0, 0);
     $pdf->setCellMargins(0, 0, 0, 0);
     $pdf->SetAutoPageBreak(false, 0);
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     if (!empty($face)) {
         // отрисуем сначала изображения лица
         foreach ($face as $item) {
             if ($item['type'] == 'image') {
                 $pdf->Image($_SERVER['DOCUMENT_ROOT'] . '/' . str_replace('http://klever.media/', '', $item['content']), $this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $this->px_to_mm($item['width']), '', '', '', '', false, 300);
             }
         }
         // потом текст на лице
         foreach ($face as $item) {
             if ($item['type'] == 'text') {
                 $cmyk = $this->rgbToCmyk($item['color']);
                 $pdf->SetTextColor($cmyk['c'] * 100, $cmyk['m'] * 100, $cmyk['y'] * 100, $cmyk['k'] * 100);
                 // set font
                 $tcpdfFont = $fontMaker->addTTFfont(realpath('fonts/redactor/' . $fonts[$item['font']]));
                 $pdf->SetFont($tcpdfFont, '', $item['size'] / 2, '', 'false');
                 $pdf->Text($this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $item['content'], false, false, true, 0, 0, 'L', false, '', 0, false, 'T', 'L', false);
             }
         }
     }
     // сохраним пдф лица
     $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/' . $face_pdf, 'F');
     // сделаем превью для пользователя
     $im = new Imagick();
     $im->setResolution(300, 300);
     $im->readimage($face_pdf . '[0]');
     $im->flattenimages();
     $im->setImageFormat('jpg');
     $im->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
     $im->writeImage($face_preview);
     $im->clear();
     $im->destroy();
     //exec('$ convert ' . $_SERVER['DOCUMENT_ROOT'] . '/' . $face_pdf . ' ' . $_SERVER['DOCUMENT_ROOT'] . '/' . $face_preview);
     // есть ли оборот
     if (!empty($backMacket)) {
         // generate pdf back template name and preview name
         $back_pdf = 'uploads/redactor/back_' . md5(microtime(true)) . '.pdf';
         $back_preview = 'uploads/redactor/back_' . md5(microtime(true)) . '.jpg';
         // convert back image to pdf
         $img = new Imagick($backMacket);
         $img->setresolution(300, 300);
         $img->setcolorspace(Imagick::COLORSPACE_CMYK);
         $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
         $img->setimageformat('pdf');
         $img->writeimage($back_pdf);
         // создаём лист
         $pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
         $pdf->AddPage('L');
         // загрузим ранее сохранённый шаблон
         $pdf->setSourceFile($_SERVER['DOCUMENT_ROOT'] . '/' . $back_pdf);
         $pdf->SetMargins(0, 0, 0, true);
         $tplIdx = $pdf->importPage(1);
         $pdf->useTemplate($tplIdx, null, null, 0, 0, true);
         // установим опции для pdf
         $pdf->SetMargins(0, 0, 0, true);
         $pdf->setCellHeightRatio(1);
         $pdf->setCellPaddings(0, 0, 0, 0);
         $pdf->setCellMargins(1, 1, 1, 1);
         $pdf->SetAutoPageBreak(false);
         $pdf->SetPrintHeader(false);
         $pdf->SetPrintFooter(false);
         if (!empty($back)) {
             // отрисуем сначала изображения оборота
             foreach ($back as $item) {
                 if ($item['type'] == 'image') {
                     $pdf->Image($_SERVER['DOCUMENT_ROOT'] . '/' . str_replace('http://klever.media/', '', $item['content']), $this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $this->px_to_mm($item['width']), '', '', '', '', false, 300);
                 }
             }
             // потом текст на обороте
             foreach ($back as $item) {
                 if ($item['type'] == 'text') {
                     $cmyk = $this->rgbToCmyk($item['color']);
                     $pdf->SetTextColor($cmyk['c'] * 100, $cmyk['m'] * 100, $cmyk['y'] * 100, $cmyk['k'] * 100);
                     // set font
                     $tcpdfFont = $fontMaker->addTTFfont($_SERVER['DOCUMENT_ROOT'] . '/fonts/redactor/' . $fonts[$item['font']]);
                     $pdf->SetFont($tcpdfFont, '', $item['size'] / 2, '', 'false');
                     $pdf->Text($this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $item['content'], false, false, true, 0, 0, 'L', false, '', 0, false, 'T', 'L', false);
                 }
             }
         }
         // сохраним пдф оборота
         $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/' . $back_pdf, 'F');
         // сделаем превью для пользователя
         $im = new Imagick();
         $im->setResolution(300, 300);
         $im->readimage($back_pdf . '[0]');
         $im->setImageFormat('jpg');
         $im->flattenimages();
         $im->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
         $im->writeImage($back_preview);
         $im->clear();
         $im->destroy();
     }
     $this->db->insert('products', array('name' => 'cards_pvc', 'tiraj' => 100, 'weight' => 0.5, 'price' => 0.49, 'cost' => 49, 'macket' => 'my_macket'));
     $product_id = $this->db->insert_id();
     $this->db->insert('designs', array('product_id' => $product_id, 'theme_id' => $this->input->post('theme'), 'face_background' => $faceMacket, 'back_background' => empty($backMacket) ? NULL : $backMacket, 'face' => $face_preview, 'back' => empty($back_preview) ? '' : $back_preview, 'type' => 'system'));
     $design_id = $this->db->insert_id();
     $options = array();
     if (!empty($face)) {
         foreach ($face as $item) {
             if ($item['type'] == 'text') {
                 $options[] = array('design_id' => $design_id, 'type' => 'text', 'front' => 'face', 'top' => $item['top'], 'left' => $item['left'], 'width' => NULL, 'height' => NULL, 'content' => $item['content'], 'font' => $item['font'], 'color' => $item['color'], 'size' => $item['size']);
             } else {
                 $options[] = array('design_id' => $design_id, 'type' => 'image', 'front' => 'face', 'top' => $item['top'], 'left' => $item['left'], 'width' => $item['width'], 'height' => $item['height'], 'content' => $item['content'], 'font' => NULL, 'color' => NULL, 'size' => NULL);
             }
         }
     }
     if (!empty($back)) {
         foreach ($back as $item) {
             if ($item['type'] == 'text') {
                 $options[] = array('design_id' => $design_id, 'type' => 'text', 'front' => 'back', 'top' => $item['top'], 'left' => $item['left'], 'width' => NULL, 'height' => NULL, 'content' => $item['content'], 'font' => $item['font'], 'color' => $item['color'], 'size' => $item['size']);
             } else {
                 $options[] = array('design_id' => $design_id, 'type' => 'image', 'front' => 'back', 'top' => $item['top'], 'left' => $item['left'], 'width' => $item['width'], 'height' => $item['height'], 'content' => $item['content'], 'font' => NULL, 'color' => NULL, 'size' => NULL);
             }
         }
     }
     if (count($options) > 0) {
         $this->db->insert_batch('design_options', $options);
     }
     echo 'OK';
 }
示例#6
0
 /**
  * @param  $image
  * @return Pimcore_Image_Adapter_Imagick
  */
 public function applyMask($image)
 {
     $image = ltrim($image, "/");
     $image = PIMCORE_DOCUMENT_ROOT . "/" . $image;
     if (is_file($image)) {
         $this->resource->setImageMatte(1);
         $newImage = new Imagick();
         $newImage->readimage($image);
         $newImage->resizeimage($this->getWidth(), $this->getHeight(), Imagick::FILTER_UNDEFINED, 1, false);
         $this->resource->compositeImage($newImage, Imagick::COMPOSITE_DSTIN, 0, 0);
     }
     $this->reinitializeImage();
     return $this;
 }
示例#7
0
 public function ResizeImage($columns, $rows, $filter = Imagick::FILTER_LANCZOS, $blur = 0)
 {
     parent::resizeimage($columns, $rows, $filter, $blur);
 }
 /**
  * @param UploadedFile $file
  * @param $entityId
  * @param $partyDir
  * @throws InvalidUploadedFile
  * @return array
  */
 private function uploadIcon(UploadedFile $file, $entityId, $partyDir)
 {
     if (strpos($file->getMimeType(), 'image/') !== 0) {
         throw new InvalidUploadedFile('Иконка должна быть картинкой PNG или JPG');
     }
     $filename = $entityId . '_icon.png';
     $path = $partyDir . '/' . $filename;
     $file->move($partyDir, $filename);
     $im = new \Imagick($path);
     $im->resizeimage(120, 110, \Imagick::FILTER_UNDEFINED, 1, true);
     $im->writeimage($path);
     return array($file, $path);
 }
示例#9
0
 public function custom_design()
 {
     $config['upload_path'] = 'uploads/redactor';
     $config['allowed_types'] = 'png|jpg|gif|pdf|tif|tiff';
     $config['max_size'] = '10000';
     $config['encrypt_name'] = true;
     $config['max_width'] = 1100;
     $config['max_height'] = 730;
     $this->load->library('upload', $config);
     if ($this->upload->do_upload()) {
         $file = $this->upload->data();
         $faceMacket = 'uploads/redactor/' . $file['raw_name'] . '.jpg';
         $img = new Imagick($file['full_path']);
         $img->flattenimages();
         $img->setimageformat('jpg');
         $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
         $img->writeimage($faceMacket);
         $this->db->insert('designs', array('product_id' => NULL, 'face' => $faceMacket, 'back' => '', 'type' => 'user'));
         $design_id = $this->db->insert_id();
         exit(json_encode(array('error' => '', 'design_id' => $design_id)));
     } else {
         exit(json_encode(array('error' => $this->upload->display_errors(' ', ' '))));
     }
 }
示例#10
0
 public function RenderImage($strPath = null)
 {
     $objImage = new Imagick();
     $objImage->ReadImage($this->strImagePath);
     // Get Image Size
     $intSourceWidth = $objImage->getimagewidth();
     $intSourceHeight = $objImage->getimageheight();
     // We need to calculate the following values:
     $intDestinationWidth = null;
     $intDestinationHeight = null;
     $intCanvasWidth = null;
     $intCanvasHeight = null;
     /////////////////////////////////////////////
     // Calculate Dimensions: Based ONLY on WIDTH
     /////////////////////////////////////////////
     if ($this->strWidth && !$this->strHeight) {
         // DIMENSIONS THE SAME -- Flow Through
         if ($this->strWidth == $intSourceWidth) {
             $intDestinationWidth = $intSourceWidth;
             $intDestinationHeight = $intSourceHeight;
             $intCanvasWidth = $intSourceWidth;
             $intCanvasHeight = $intSourceHeight;
             // DESTINATION LARGER than source
         } else {
             if ($this->strWidth > $intSourceWidth) {
                 // Do NOT Scale "Up"
                 if (!$this->blnScaleImageUp) {
                     // Scale Canvas -- Flow Through
                     if ($this->blnScaleCanvasDown) {
                         $intDestinationWidth = $intSourceWidth;
                         $intDestinationHeight = $intSourceHeight;
                         $intCanvasWidth = $intSourceWidth;
                         $intCanvasHeight = $intSourceHeight;
                         // Do NOT Scale Canvas -- Canvas width matches requested width. Destionation matches Source dimensions.
                     } else {
                         $intDestinationWidth = $intSourceWidth;
                         $intDestinationHeight = $intSourceHeight;
                         $intCanvasWidth = $this->strWidth;
                         $intCanvasHeight = $intSourceHeight;
                     }
                     // SCALE UP source image -- Canvas and Destination widths both match requested width.  Canvas and Destination height both need to scale up.
                 } else {
                     $intDestinationWidth = $this->strWidth;
                     $intDestinationHeight = $intSourceHeight * $this->strWidth / $intSourceWidth;
                     $intCanvasWidth = $this->strWidth;
                     $intCanvasHeight = $intSourceHeight * $this->strWidth / $intSourceWidth;
                 }
                 // DESTINATION SMALLER than source -- Scale Down Source Image.  Canvas is size of image
             } else {
                 $intDestinationWidth = $this->strWidth;
                 $intDestinationHeight = $intSourceHeight * $this->strWidth / $intSourceWidth;
                 $intCanvasWidth = $intDestinationWidth;
                 $intCanvasHeight = $intDestinationHeight;
             }
         }
         /////////////////////////////////////////////
         // Calculate Dimensions: Based ONLY on HEIGHT
         /////////////////////////////////////////////
     } else {
         if ($this->strHeight && !$this->strWidth) {
             // DIMENSIONS THE SAME -- Flow Through
             if ($this->strHeight == $intSourceHeight) {
                 $intDestinationWidth = $intSourceWidth;
                 $intDestinationHeight = $intSourceHeight;
                 $intCanvasWidth = $intSourceWidth;
                 $intCanvasHeight = $intSourceHeight;
                 // DESTINATION LARGER than source
             } else {
                 if ($this->strHeight > $intSourceHeight) {
                     // Do NOT Scale "Up"
                     if (!$this->blnScaleImageUp) {
                         // Scale Canvas -- Flow Through
                         if ($this->blnScaleCanvasDown) {
                             $intDestinationWidth = $intSourceWidth;
                             $intDestinationHeight = $intSourceHeight;
                             $intCanvasWidth = $intSourceWidth;
                             $intCanvasHeight = $intSourceHeight;
                             // Do NOT Scale Canvas -- Canvas height matches requested height. Destionation matches Source dimensions.
                         } else {
                             $intDestinationWidth = $intSourceWidth;
                             $intDestinationHeight = $intSourceHeight;
                             $intCanvasWidth = $intSourceWidth;
                             $intCanvasHeight = $this->strHeight;
                         }
                         // SCALE UP source image -- Canvas and Destination heights both match requested height.  Canvas and Destination widths both need to scale up.
                     } else {
                         $intDestinationWidth = $intSourceWidth * $this->strHeight / $intSourceHeight;
                         $intDestinationHeight = $this->strHeight;
                         $intCanvasWidth = $intSourceWidth * $this->strHeight / $intSourceHeight;
                         $intCanvasHeight = $this->strHeight;
                     }
                     // DESTINATION SMALLER than source -- Scale Down Source Image.  Canvas is size of image
                 } else {
                     $intDestinationWidth = $intSourceWidth * $this->strHeight / $intSourceHeight;
                     $intDestinationHeight = $this->strHeight;
                     $intCanvasWidth = $intDestinationWidth;
                     $intCanvasHeight = $intDestinationHeight;
                 }
             }
             /////////////////////////////////////////////
             // Calculate Dimensions based on BOTH DIMENSIONS
             /////////////////////////////////////////////
         } else {
             // DIMENSIONS THE SAME -- Flow Through
             if ($this->strHeight == $intSourceHeight && $this->strWidth == $intSourceWidth) {
                 $intDestinationWidth = $intSourceWidth;
                 $intDestinationHeight = $intSourceHeight;
                 $intCanvasWidth = $intSourceWidth;
                 $intCanvasHeight = $intSourceHeight;
                 // DESTINATION LARGER than source
             } else {
                 if ($this->strHeight >= $intSourceHeight && $this->strWidth >= $intSourceWidth) {
                     // Do NOT Scale "Up"
                     if (!$this->blnScaleImageUp) {
                         // Scale Canvas - Flow Through
                         if ($this->blnScaleCanvasDown) {
                             $intDestinationWidth = $intSourceWidth;
                             $intDestinationHeight = $intSourceHeight;
                             $intCanvasWidth = $intSourceWidth;
                             $intCanvasHeight = $intSourceHeight;
                             // Do NOT Scale Canvas -- Canvas Dimensions match Requested Dimensions.  Destination dimensions match Source Dimensions
                         } else {
                             $intDestinationWidth = $intSourceWidth;
                             $intDestinationHeight = $intSourceHeight;
                             $intCanvasWidth = $this->strWidth;
                             $intCanvasHeight = $this->strHeight;
                         }
                     }
                 }
             }
             // If no Dest Width is defined, then we haven't done any calculations yet.  This means that we are either
             // scaling up OR down the source image.  Scale Destination Dimensions to the maximum possible, given the requested width/height
             if (!$intDestinationWidth) {
                 // Calculate Image Proportions for Source and Destination
                 $fltSourceProportions = $intSourceWidth / $intSourceHeight;
                 $fltDestProportions = $this->strWidth / $this->strHeight;
                 // Destination is WIDER than Source -- therefore HEIGHT defined by Requested Height, and Width is calculated
                 if ($fltDestProportions > $fltSourceProportions) {
                     $intDestinationWidth = $intSourceWidth * $this->strHeight / $intSourceHeight;
                     $intDestinationHeight = $this->strHeight;
                     // Destination is TALLER than Source -- therefore WIDTH defined by Requested Width, and Height is calculated
                 } else {
                     if ($fltDestProportions < $fltSourceProportions) {
                         $intDestinationWidth = $this->strWidth;
                         $intDestinationHeight = $intSourceHeight * $this->strWidth / $intSourceWidth;
                         // Destination Proportions MATCH Source Proportions -- Width/Height defined by Requested Width/Height
                     } else {
                         $intDestinationWidth = $this->strWidth;
                         $intDestinationHeight = $this->strHeight;
                         $intCanvasWidth = $intDestinationWidth;
                         $intCanvasHeight = $intDestinationHeight;
                     }
                 }
             }
             // If No Canvas Dimensions Defined, Calculate this now
             if (!$intCanvasWidth) {
                 if ($this->blnScaleCanvasDown) {
                     $intCanvasWidth = $intDestinationWidth;
                     $intCanvasHeight = $intDestinationHeight;
                 } else {
                     $intCanvasWidth = $this->strWidth;
                     $intCanvasHeight = $this->strHeight;
                 }
             }
         }
     }
     $objImage->resizeimage($intDestinationWidth, $intDestinationHeight, imagick::FILTER_QUADRATIC, 0.5);
     // Calculate X and Y position
     $intX = round(($intCanvasWidth - $intDestinationWidth) / 2.0);
     $intY = round(($intCanvasHeight - $intDestinationHeight) / 2.0);
     // Create Destination Image
     $objFinalImage = new Imagick();
     $objFinalImage->NewImage($intCanvasWidth, $intCanvasHeight, new ImagickPixel('#' . $this->strBackColor));
     $objFinalImage->CompositeImage($objImage, imagick::COMPOSITE_DEFAULT, $intX, $intY);
     $this->RenderImageMagickHelper($objFinalImage, $strPath);
 }
示例#11
0
 public function setAvatar($userInfo, $source)
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $people = Ml_Model_People::getInstance();
     $s3config = $config['services']['S3'];
     $s3 = new Zend_Service_Amazon_S3($s3config['key'], $s3config['secret']);
     try {
         $im = new Imagick($source);
         $im->setimagecompressionquality(self::$_imageQuality);
         $dim = $im->getimagegeometry();
         if (!$dim) {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
     $sizesInfo = array();
     $tmpFilenames = array();
     $im->unsharpMaskImage(0, 0.5, 1, 0.05);
     foreach ($this->_sizes as $sizeInfo) {
         $tmpFilenames[$sizeInfo[1]] = tempnam(sys_get_temp_dir(), 'HEADSHOT');
         if ($sizeInfo[0] == "sq") {
             if ($dim['height'] < $dim['width']) {
                 $size = $dim['height'];
             } else {
                 $size = $dim['width'];
             }
             //@todo let the user crop using Javascript, so he/she can set the offsets (default 0,0)
             $im->cropThumbnailImage($sizeInfo[3], $sizeInfo[3]);
         } else {
             if ($dim['width'] < $sizeInfo[3] && $dim['height'] < $sizeInfo[3] && $sizeInfo[2] != 'huge') {
                 copy($source, $tmpFilenames[$sizeInfo[1]]);
             } else {
                 if ($dim['width'] > $dim['height']) {
                     $im->resizeimage($sizeInfo[3], 0, Imagick::FILTER_LANCZOS, 1);
                 } else {
                     $im->resize(0, $sizeInfo[3], Imagick::FILTER_LANCZOS, 1);
                 }
             }
         }
         $im->writeimage($tmpFilenames[$sizeInfo[1]]);
         $imGeometry = $im->getimagegeometry();
         $sizesInfo[$sizeInfo[0]] = array("w" => $imGeometry['width'], "h" => $imGeometry['height']);
     }
     $oldData = unserialize($userInfo['avatarInfo']);
     //get the max value of mt_getrandmax() or the max value of the unsigned int type
     if (mt_getrandmax() < 4294967295.0) {
         $maxRand = mt_getrandmax();
     } else {
         $maxRand = 4294967295.0;
     }
     $newSecret = mt_rand(0, $maxRand);
     if (isset($oldData['secret'])) {
         while ($oldData['secret'] == $newSecret) {
             $newSecret = mt_rand(0, $maxRand);
         }
     }
     foreach ($tmpFilenames as $size => $file) {
         if ($size == '_h') {
             $privacy = Zend_Service_Amazon_S3::S3_ACL_PRIVATE;
         } else {
             $privacy = Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ;
         }
         $picAddr = $s3config['headshotsBucket'] . "/" . $userInfo['id'] . '-' . $newSecret . $size . '.jpg';
         $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => $privacy, "Content-Type" => Zend_Service_Amazon_S3::getMimeType($picAddr), "Cache-Control" => "max-age=37580000, public", "Expires" => "Thu, 10 May 2029 00:00:00 GMT");
         $s3->putFile($file, $picAddr, $meta);
         unlink($file);
     }
     $newAvatarInfo = serialize(array("sizes" => $sizesInfo, "secret" => $newSecret));
     $people->update($userInfo['id'], array("avatarInfo" => $newAvatarInfo));
     //delete the old files
     $this->deleteFiles($userInfo);
     return true;
 }
示例#12
0
 /**
  * Primary processing routine for the source
  */
 private function processBook()
 {
     // Get Media manager and preset page parameters
     $mediaManager = new MediaManager($this->bookId);
     $pageCount = count($this->sourceFiles) + count($this->sourceAssets);
     $pageNumber = 1;
     // Prepare the progress
     $this->progress->startProgress($pageCount * 2);
     $this->updatePageCount(0);
     $bookSizeFound = false;
     // Loop through source files
     foreach ($this->sourceFiles as $source) {
         CakeLog::debug('[ImageProcessor::processBook] processing source file ' . $source);
         // Get book size
         if (!$bookSizeFound) {
             $bookWidth = 0;
             $bookHeight = 0;
             $this->getBookSizeImage($source, $bookWidth, $bookHeight);
             CakeLog::debug('[ImageProcessor::processBook] Book dimensions set to ' . $bookWidth . ' x ' . $bookHeight);
             $this->updateBookSize($bookWidth, $bookHeight);
             $bookSizeFound = true;
         }
         // Convert to png as needed
         if (MediaManager::isConvertableImage($source)) {
             CakeLog::debug('[ImageProcessor::processBook] Converting ' . $source . ' to png');
             $mediaManager->imageConvertToPng($source, $source);
         }
         // Resize image to max dimension.
         $image = new Imagick($source);
         $width = $image->getimagewidth();
         $height = $image->getimageheight();
         // Get new width and height
         list($newWidth, $newHeight) = $this->getResizedDimensionsForMaxPixels($width, $height);
         if ($newHeight != $height || $newWidth != $width) {
             CakeLog::debug('[ImageProcessor::processBook] ' . $source . ' resized for max pixel limits to ' . $newWidth . 'x' . $newHeight);
             // Resize the original image
             $img = new Imagick($source);
             $img->resizeimage($newWidth, $newHeight, Imagick::FILTER_LANCZOS, 1, false);
             $img->writeimage();
         }
         $this->addImageAssetToBook($source, 'images/backgrounds/');
         $this->savePageHTML('', $pageNumber, null, '../images/backgrounds/' . basename($source));
         @unlink($source);
         $this->savePageCSS('', $pageNumber);
         // Count page
         $pageNumber++;
         // Update the progress in database every 10th page.
         $this->progress->incrementStep();
     }
     //handle any non-source assets included with the book source files
     $this->importSourceAssets();
     $this->setCoverImage();
     // Save default book CSS
     $this->saveBookCSS('');
     // Generate thumbnails
     $this->generateThumbnails(1, $pageCount);
     $this->updatePageCount($pageCount);
     CakeLog::debug('[ImageProcessor::processBook] Book Processing Complete');
 }
示例#13
0
文件: main.php 项目: n0rp3d/klever
 public function test()
 {
     //        $rgb_arr = sscanf('rgb(243, 243, 243)', "rgb(%d, %d, %d)");
     //        print_r($this->rgbToCmyk($rgb_arr[0], $rgb_arr[1], $rgb_arr[2]));
     //        exit();
     //
     $img = new Imagick('test.jpg');
     $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
     $img->setresolution(300, 300);
     $img->setimageformat('pdf');
     $img->writeimage('test.pdf');
     include_once APPPATH . 'libraries/tcpdf/tcpdf.php';
     include_once APPPATH . 'libraries/tcpdf/fpdi.php';
     // создаём лист
     $pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
     $pdf->AddPage('L');
     // загрузим ранее сохранённый шаблон
     $pdf->setSourceFile('test.pdf');
     $pdf->SetMargins(0, 0, 0, true);
     $tplIdx = $pdf->importPage(1);
     $pdf->useTemplate($tplIdx, null, null, 0, 0, true);
     // установим опции для pdf
     $pdf->SetMargins(0, 0, 0, true);
     $pdf->setCellHeightRatio(1);
     $pdf->setCellPaddings(0, 0, 0, 0);
     $pdf->setCellMargins(1, 1, 1, 1);
     $pdf->SetAutoPageBreak(false);
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     $pdf->Image('qwe.png', 30, 30, 20, '', '', '', '', false, 300);
     $pdf->SetTextColor(0, 0, 0, 100);
     $pdf->SetFont('helvetica', 'BI', 10, '', 'false');
     $pdf->Text(12, 9, 'Black CMYK');
     $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/uploads/fynal.pdf', 'F');
     $im = new Imagick();
     $im->setResolution(300, 300);
     $im->readimage('uploads/fynal.pdf[0]');
     $im->setImageFormat('jpeg');
     $im->resizeimage(538, 360, Imagick::FILTER_LANCZOS, 1);
     $im->writeImage('uploads/fynal.jpg');
     $im->clear();
     $im->destroy();
     //        include_once APPPATH . 'libraries/drawer.php';
     //
     //        $drawer = new Drawer();
     //        $drawer->init();
     //        $drawer->setLayout();
     //        $drawer->setBackground('test.jpg');
     //        $drawer->drawImage('test.jpg', 10, 10, 30);
     //        $drawer->drawText('Maxim', 10, 10, 'TimesNewRoman', 20, 'rgb(77, 77, 77)');
     //        $drawer->savePdf($_SERVER['DOCUMENT_ROOT'] . '/1.pdf');
     //        $drawer->makePreview($_SERVER['DOCUMENT_ROOT'] . '/1.pdf', $_SERVER['DOCUMENT_ROOT'] . '/1.jpg');
 }
示例#14
0
 private function _gatherSourceImages()
 {
     $this->_debug('Gathering source images...');
     $images = array();
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $file_types = explode('|', $this->config['source_image_format']);
     if ($dh = opendir($this->config['source_image_folder'])) {
         while (($file = readdir($dh)) !== false) {
             if (in_array(str_replace('image/', '', finfo_file($finfo, $this->config['source_image_folder'] . $file)), $file_types)) {
                 $images[] = $this->config['source_image_folder'] . $file;
             }
         }
     }
     finfo_close($finfo);
     if (count($images) == 0) {
         show_error('No source images found');
     }
     $this->_debug('...determining average color for each source image...');
     for ($i = 0; $i < count($images); $i++) {
         $imagick = $orig = null;
         // memory reset
         //if($i > 30)
         //	break;
         $imagick = new Imagick(realpath($images[$i]));
         $rgb_str = $imagick->getimageproperty($this->image_property);
         if ($rgb_str === false || $this->config['update_cache']) {
             if (!$imagick->resizeimage(1, 1, $this->resize_filter, 1)) {
                 show_error('Failed to manipulate source image in order to determine averge color');
             }
             $pixel = $imagick->getimagepixelcolor(0, 0);
             $orig = new Imagick(realpath($images[$i]));
             $this->image_bank[$i] = array_merge(array('orig_file' => str_replace(getcwd(), '', $images[$i])), $pixel->getcolor());
             $val = implode('|', $pixel->getcolor());
             $this->_debug('...caching ' . $val . ' on ' . $this->image_bank[$i]['orig_file'] . '...');
             $orig->setimageproperty($this->image_property, $val);
             $orig->writeimage($images[$i]);
         } else {
             $pieces = array_pad(explode('|', $rgb_str), 4, 0);
             $this->image_bank[$i] = array_merge(array('orig_file' => str_replace(getcwd(), '', $images[$i])), array('r' => $pieces[0], 'g' => $pieces[1], 'b' => $pieces[2], 'a' => $pieces[3]));
             $this->_debug('...using image cache (' . $rgb_str . ') from ' . $this->image_bank[$i]['orig_file'] . '...');
         }
     }
     $this->_debug('...determined average color for ' . count($this->image_bank) . ' images!');
     $this->_debug('Source images gathered!');
 }
示例#15
0
 /**
  * Resize file if it is image (getimagesize return 0 with for non image file)
  *
  * @param string $path
  */
 public function resizeImage($path)
 {
     $maxWidthHeight = $this->maxResizeWidth;
     $imageData = getimagesize($path);
     if ($imageData[0] !== 0 && ($imageData[0] > $maxWidthHeight || $imageData[1] > $maxWidthHeight)) {
         $imagick = new \Imagick($path);
         $imagick->resizeimage($maxWidthHeight, $maxWidthHeight, \Imagick::FILTER_POINT, 1, true);
         $imagick->writeimage($path);
     }
 }