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(); }
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 }
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; }
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); }
/** * 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(); }
/** * 获取图片尺寸 * @return array */ public function getSize() { $wh = []; $wh['width'] = $this->image->getImageWidth(); $wh['height'] = $this->image->getImageHeight(); return $wh; }
/** * @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; }
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); }
public function testImageWorkingType() { $file100 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-100-ffa94c'); $image = new Imagick(); $image->readimageblob($file100['contents']); $this->assertEquals(100, $image->getImageWidth()); $file200 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-200-ffa94c'); $image->readimageblob($file200['contents']); $this->assertEquals(200, $image->getImageWidth()); }
/** * @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(); }
/** * @return \ImageStorage\Image\Structure\Image * @throws \Exception */ private function _watermark_rand() { if (false === file_exists($this->_watermarkRand->fileName)) { throw new \Exception('File ' . $this->_watermarkRand->fileName . ' not exist!'); } $config = $this->_watermarkRand; if (false === class_exists('\\Imagick')) { return $this->_imageStruct; } //prepare source in Imagick $source = new \Imagick(); $source->readImageBlob($this->getJpgBlobFromGd($this->_imageStruct->image)); //prepare watermark $watermark = new \Imagick($this->_watermarkRand->fileName); $maxWatermarkSize = $source->getImageWidth() * $config->getSize(); if ($maxWatermarkSize < $config->getMinSize()) { $maxWatermarkSize = $config->getMinSize(); } $watermark->thumbnailImage($maxWatermarkSize, $maxWatermarkSize); //cache image size $imageWidth = $source->getImageWidth(); $imageHeight = $source->getImageHeight(); //set max watermarks $maxCols = $imageWidth / $config->getMinSize() / 2; if ($maxCols < $config->getCols()) { $config->setCols(ceil($maxCols)); } $maxRows = $imageHeight / $config->getMinSize() / 2; if ($maxRows < $config->getRows()) { $config->setRows(ceil($maxRows)); } //step width $stepWidth = $imageWidth / $config->getCols(); $stepHeight = $imageHeight / $config->getRows(); //put images for ($row = 0; $row < $config->getRows(); $row++) { for ($col = 0; $col < $config->getCols(); $col++) { $x = rand($col * $stepWidth, ($col + 1) * $stepWidth); $y = rand($row * $stepHeight, ($row + 1) * $stepHeight); //make sure that watermark is in image bound if ($x + $maxWatermarkSize > $imageWidth) { $x = $imageWidth - $maxWatermarkSize; } if ($y + $maxWatermarkSize > $imageHeight) { $y = $imageHeight - $maxWatermarkSize; } //put watermark to image $source->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $x, $y); } } $source->setImageFormat("jpeg"); $this->_imageStruct->image = imagecreatefromstring($source->getImageBlob()); return $this->_imageStruct; }
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; }
protected function _sharpen($amount) { //IM not support $amount under 5 (0.15) $amount = $amount < 5 ? 5 : $amount; $amount = $amount * 13.0 / 100; if ($this->im->sharpenImage(0, $amount)) { $this->width = $this->im->getImageWidth(); $this->height = $this->im->getImageHeight(); return true; } return false; }
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> "; 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 }
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; }
private function _getSourceType(Imagick $image) { if ($image->getImageWidth() > 1920 && $image->getImageHeight() > 1080) { return Job::WQXGA; } return Job::FHD; }
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; } }
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); } }
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; }
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; }
function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom) { //The blur factor where > 1 is blurry, < 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(); }
/** * {@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); }
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; }
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); }
/** * @return array */ public function getDimensions() { if ($vectorDimensions = $this->getVectorFormatEmbeddedRasterDimensions()) { return $vectorDimensions; } return ["width" => $this->resource->getImageWidth(), "height" => $this->resource->getImageHeight()]; }
/** * 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(); }
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]); }
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(); }
/** * 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); }