public function RenderImage($strPath = null) { $objTextColor = new ImagickPixel('#eafaea'); $objTextColorShadow = new ImagickPixel('#163616'); $objBackgroundColor = new ImagickPixel('#5c5c5c'); $this->objImage = new IMagick(); $this->objImage->NewImage($this->strWidth * $this->intQuality, $this->strHeight * $this->intQuality, $objBackgroundColor); $this->objDraw = new IMagickDraw(); // Overlay Shade $objNewImage = new IMagick(__DOCROOT__ . '/images/mask.png'); $objNewImage->ResizeImage($this->strWidth * $this->intQuality, $this->strHeight * $this->intQuality, IMagick::FILTER_GAUSSIAN, 0.7); $this->objImage->CompositeImage($objNewImage, Imagick::COMPOSITE_MULTIPLY, 0, 0); // Draw Text $this->objDraw->setStrokeColor($objTextColorShadow); $this->objDraw->setFillColor($objTextColorShadow); $this->objDraw->SetFont(__QCODO__ . '/fonts/Formata-Bold.pfb'); $this->SetFontSize(12); $this->DrawText('PHP DEVELOPMENT FRAMEWORK', 159.5, 49.5); $this->objDraw->setStrokeColor($objTextColor); $this->objDraw->setFillColor($objTextColor); $this->DrawText('PHP DEVELOPMENT FRAMEWORK', 158, 48); // Scale Down $this->objImage->ResizeImage($this->strWidth, $this->strHeight, Imagick::FILTER_GAUSSIAN, 0.7); $objLogo = new IMagick(__DOCROOT__ . '/images/qcodo_logo_2.png'); $objLogo->ResizeImage(380 * 0.4, 132 * 0.4, Imagick::FILTER_GAUSSIAN, 0.7); $this->objImage->CompositeImage($objLogo, Imagick::COMPOSITE_OVER, 4, 2); return $this->RenderImageMagickHelper($this->objImage, $strPath); }
public function RenderImage($strPath = null) { $objTextColor = new ImagickPixel('#bbbbbb'); $objBackgroundColor = new ImagickPixel('#393939'); $objBackgroundColorHighlight = new ImagickPixel('#606060'); $objBackgroundColorHighlightLess = new ImagickPixel('#404040'); // Create Objects $this->objImage = new IMagick(); $this->objImage->NewImage($this->strWidth * $this->intQuality, $this->strHeight * $this->intQuality, $objBackgroundColor); $this->objDraw = new IMagickDraw(); // Overlay Shade $objNewImage = new IMagick(__DOCROOT__ . '/images/mask.png'); $objNewImage->ResizeImage($this->strWidth * $this->intQuality, $this->strHeight * $this->intQuality, IMagick::FILTER_GAUSSIAN, 0.7); $this->objImage->CompositeImage($objNewImage, Imagick::COMPOSITE_MULTIPLY, 0, 0); // $this->objDraw->setStrokeColor($objBackgroundColorHighlight); // $this->DrawHorizontalLine(0, $this->strWidth, 0); // $this->objDraw->setStrokeColor($objBackgroundColorHighlightLess); // $this->DrawHorizontalLine(0, $this->strWidth, 1); $this->objDraw = new IMagickDraw(); $this->objDraw->SetFont($this->Font); $this->SetFontSize($this->FontSize); $this->objDraw->setStrokeColor($objTextColor); $this->objDraw->setFillColor($objTextColor); $this->DrawText($this->Text, $this->XPosition, $this->YPosition); // Scale Down $this->objImage->ResizeImage($this->strWidth, $this->strHeight, Imagick::FILTER_GAUSSIAN, 0.7); return $this->RenderImageMagickHelper($this->objImage, $strPath); }
function buildImage($opts) { $input = "input/2010_09_04__23_56_32_125__SDO_AIA_AIA_304.pgm"; $clut = "input/SDO_AIA_304.png"; $image = new IMagick($input); if ($opts['use_gd']) { // Format if ($opts['inter_format']) { $image->setImageFormat($opts['inter_format']); } // Bit-depth (intermediate image) if ($opts['depth']) { $image->setImageDepth($opts['depth']); } // Image type if ($opts['type']) { $image->setImageType(constant($opts['type'])); } // Compression quality if ($opts['input_quality'] || $opts['input_quality'] === 0) { $image->setImageCompressionQuality($opts['input_quality']); } $intermediate = $image->getimageblob(); if ($opts['base64']) { $intermediate = base64_encode($intermediate); } $image->destroy(); $coloredImage = setColorPalette($intermediate, $clut, $opts['base64']); if ($opts['base64']) { $coloredImage = base64_decode($coloredImage); } $image = new IMagick(); $image->readimageblob($coloredImage); } else { $image->clutImage(new Imagick($clut)); } if (strtolower($opts["output_format"]) == "png") { // Compression type if ($opts['compression']) { $image->setImageCompression(constant($opts['compression'])); } // Interlacing if ($opts['interlace']) { $image->setInterlaceScheme(constant($opts['interlace'])); } // Compression quality if ($opts['output_quality'] || $opts['output_quality'] === 0) { $image->setImageCompressionQuality($opts['output_quality']); } } // Bit-depth (final image) if ($opts['depth']) { $image->setImageDepth($opts['depth']); } $image->writeImage("final." . strtolower($opts["output_format"])); $image->destroy(); }
function upload() { // Default settings/restrictions $config['upload_path'] = $this->directory; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = min(maxUploadSizeBytes() / 1024, self::MAX_FILE_SIZE_KB); $config['max_width'] = '0'; // no restriction (image will be resized anyway!) $config['max_height'] = '0'; $config['max_filename'] = self::MAX_FILE_NAME_LEN; $this->load->library('upload', $config); // Try and upload the file using the settings from __construct() if (!$this->upload->do_upload('new_file')) { // Abort upload and display errors, if any $data['error_message'] = $this->upload->display_errors(); $data['recent_uploads'] = $this->getRecentUploads(); $data['title'] = "Image Uploader"; $data['js_lib'] = array('core'); $this->load->view('uploader', $data); } else { // Create the compressed copy of the image based on a hash of the uploaded filename $upload_result = $this->upload->data(); $image = new Imagick($this->directory . $upload_result['file_name']); $image->setBackgroundColor(new ImagickPixel('white')); // Create the optimised image // "bestfit" param will ensure that the image is downscaled proportionally if needed // if ($image->getImageWidth() >= $image->getImageHeight() // && $image->getImageWidth() > self::IMAGE_LANDSCAPE_WIDTH || $image->getImageHeight() > self::IMAGE_LANDSCAPE_HEIGHT) // { // $image->resizeImage(self::IMAGE_LANDSCAPE_WIDTH,self::IMAGE_LANDSCAPE_HEIGHT, Imagick::FILTER_LANCZOS, 1, true); // } // else if ($image->getImageWidth() > self::IMAGE_PORTRAIT_WIDTH || $image->getImageHeight() > self::IMAGE_PORTRAIT_HEIGHT) // { // $image->resizeImage(self::IMAGE_PORTRAIT_WIDTH,self::IMAGE_PORTRAIT_HEIGHT, Imagick::FILTER_LANCZOS, 1, true); // } $flattened = new IMagick(); $flattened->newImage($image->getImageWidth(), $image->getImageHeight(), new ImagickPixel("white")); $flattened->compositeImage($image, imagick::COMPOSITE_OVER, 0, 0); $flattened->setImageFormat("jpg"); $flattened->setImageCompression(Imagick::COMPRESSION_JPEG); // $flattened->setCompression(Imagick::COMPRESSION_JPEG); // $flattened->setCompressionQuality(self::COMPRESSION_PERCENTAGE); $flattened->writeImage($this->directory . 'img_' . md5($upload_result['file_name']) . ".jpg"); $flattened->clear(); $flattened->destroy(); $image->clear(); $image->destroy(); $data['success_message'] = "File successfully uploaded!"; $data['recent_uploads'] = $this->getRecentUploads(); $data['title'] = "Image Uploader"; $data['js_lib'] = array('core'); $data['max_filesize'] = $config['max_size']; $this->load->view('uploader', $data); } }
/** * Composites a watermark (the date strings of the image) onto the lower * left corner and the HV logo in the lower right corner. * * Layer names are added together as one string, and date strings are * added as a separate string, to line them up nicely. An example string * would be: * * -annotate +20+0 'EIT 304\nLASCO C2\n' * and: * -annotate +100+0 '2003-01-01 12:00\n2003-01-01 11:30\n' * * These two strings are then layered on top of each other and put in the * southwest corner of the image. * * @param object $imagickImage An Imagick object * * @return void */ private function _addWatermark($imagickImage) { if ($this->width < 200 || $this->height < 200) { return; } $watermark = new IMagick(HV_ROOT_DIR . '/resources/images/' . 'watermark_small_black_border.png'); // If the image is too small, use only the circle, not the url, and // scale it so it fits the image. if ($this->width / 300 < 2) { $watermark->readImage(HV_ROOT_DIR . '/resources/images/' . 'watermark_circle_small_black_border.png'); $scale = $this->width / 2 / 300; $width = $watermark->getImageWidth(); $watermark->scaleImage($width * $scale, $width * $scale); } // For whatever reason, compositeImage() doesn't carry over gravity // settings so the offsets must be relative to the top left corner of // the image rather than the desired gravity. $x = $this->width - $watermark->getImageWidth() - 10; $y = $this->height - $watermark->getImageHeight() - 10; $imagickImage->compositeImage($watermark, IMagick::COMPOSITE_DISSOLVE, $x, $y); // If the image is too small, text won't fit. Don't put a date string // on it. if ($this->width > 285) { $this->_addTimestampWatermark($imagickImage); } // Cleanup $watermark->destroy(); }
public function resize($maxwidth = 0, $maxheight = 0, $opts = array()) { $config = self::getConfig(); if ($config['cache'] && ($cache = $this->getCache())) { $this->_data = $cache; return $this->_data; } if (is_array($maxwidth)) { $opts = $maxwidth; } else { $opts['width'] = $maxwidth; $opts['height'] = $maxheight; } $origWidth = $width = $this->_imagesize[0]; $origHeight = $height = $this->_imagesize[1]; if (isset($opts['color'])) { $color = preg_replace('/[^0-9a-fA-F]/', '', (string) $opts['color']); } else { $color = FALSE; } if ((!isset($opts['width']) || !$opts['width']) && isset($opts['height'])) { $opts['width'] = 99999999999999.0; } elseif (isset($opts['width']) && (!isset($opts['height']) || !$opts['height'])) { $opts['height'] = 99999999999999.0; } if (!isset($opts['width'])) { $opts['width'] = $width; } if (!isset($opts['height'])) { $opts['height'] = $height; } $offsetX = 0; $offsetY = 0; if (isset($opts['ratio']) && $opts['ratio']) { //$cropRatio = explode(':', (string) $opts['ratio']); $cropRatio = array($opts['width'], $opts['height']); if (sizeof($cropRatio) == 2) { $ratioComputed = $width / $height; $cropRatioComputed = (double) $cropRatio[0] / (double) $cropRatio[1]; if ($ratioComputed < $cropRatioComputed) { $origHeight = $height; $height = $width / $cropRatioComputed; $offsetY = ($origHeight - $height) / 2; } else { if ($ratioComputed > $cropRatioComputed) { $origWidth = $width; $width = $height * $cropRatioComputed; $offsetX = ($origWidth - $width) / 2; } } } } if (isset($opts["x"])) { $offsetX = (int) $opts["x"]; } if (isset($opts["y"])) { $offsetY = (int) $opts["y"]; } $xRatio = $opts['width'] / $width; $yRatio = $opts['height'] / $height; if ($xRatio * $height < $opts['height']) { $tnHeight = ceil($xRatio * $height); $tnWidth = $opts['width']; } else { $tnWidth = ceil($yRatio * $width); $tnHeight = $opts['height']; } // Determine the quality of the output image $quality = isset($opts['quality']) ? (int) $opts['quality'] : $config['quality']; $resizeFactor = isset($opts['scale']) && (double) $opts['scale'] != 0 ? (double) $opts['scale'] : 1; if (isset($opts['crop']) && sizeof($cropRatio) == 2) { $dst = imagecreatetruecolor($cropRatio[0] * $resizeFactor, $cropRatio[1] * $resizeFactor); //$dst = imagecreatetruecolor($cropRatio[0], $cropRatio[1]); } else { $dst = imagecreatetruecolor($tnWidth * $resizeFactor, $tnHeight * $resizeFactor); //$dst = imagecreatetruecolor($tnWidth, $tnHeight*$resizeFactor); } switch ($this->_mime) { case 'image/gif': $creationFunction = 'imagecreatefromgif'; $outputFunction = 'imagepng'; $mime = 'image/png'; // We need to convert GIFs to PNGs $doSharpen = FALSE; $quality = round(10 - $quality / 10); break; case 'image/x-png': case 'image/png': $creationFunction = 'imagecreatefrompng'; $outputFunction = 'imagepng'; $doSharpen = FALSE; $quality = round(10 - $quality / 10); // PNG needs a compression level of 0 (no compression) through 9 break; default: $creationFunction = 'imagecreatefromjpeg'; $outputFunction = 'imagejpeg'; $doSharpen = TRUE; break; } // Read in the original image $src = $creationFunction($this->_filename); if (in_array($this->_mime, array('image/gif', 'image/png'))) { if (!$color) { // If this is a GIF or a PNG, we need to set up transparency imagealphablending($dst, false); imagesavealpha($dst, true); } else { // Fill the background with the specified color for matting purposes if ($color[0] == '#') { $color = substr($color, 1); } $background = FALSE; if (strlen($color) == 6) { $background = imagecolorallocate($dst, hexdec($color[0] . $color[1]), hexdec($color[2] . $color[3]), hexdec($color[4] . $color[5])); } else { if (strlen($color) == 3) { $background = imagecolorallocate($dst, hexdec($color[0] . $color[0]), hexdec($color[1] . $color[1]), hexdec($color[2] . $color[2])); } } if ($background) { imagefill($dst, 0, 0, $background); } } } if (isset($opts['crop']) && !empty($opts['crop'])) { if ($width > $height) { $destW = $tnWidth / $tnHeight * $height * ($cropRatio[0] / $tnWidth); $destH = $height * ($cropRatio[0] / $tnWidth); } else { $destH = $tnHeight / $tnWidth * $width * ($cropRatio[0] / $tnWidth); $destW = $width * ($cropRatio[0] / $tnWidth); } } else { if (isset($opts['crop_width']) && isset($opts['crop_height'])) { $destW = (int) $opts['crop_width']; $destH = (int) $opts['crop_height']; $width = $origWidth; $height = $origHeight; $offsetX = $offsetX * ($width / $destW); $offsetY = $offsetY * ($height / $destH); } else { $destH = $tnHeight; $destW = $tnWidth; } } $w = $width; $h = $height; $dw = $destW * $resizeFactor; //$dw = $destW; $dh = $destH * $resizeFactor; //$dh = $destH; // Resample the original image into the resized canvas we set up earlier imagecopyresampled($dst, $src, 0, 0, $offsetX, $offsetY, $dw, $dh, $w, $h); if ($doSharpen) { $sharpness = self::findSharp($width, $tnWidth); $sharpenMatrix = array(array(-1, -2, -1), array(-2, $sharpness + 12, -2), array(-1, -2, -1)); $divisor = $sharpness; $offset = 0; imageconvolution($dst, $sharpenMatrix, $divisor, $offset); } if (isset($opts['blackwhite']) && $opts['blackwhite']) { for ($c = 0; $c < 256; $c++) { $palette[$c] = imagecolorallocate($dst, $c, $c, $c); } //Creates yiq function function yiq($r, $g, $b) { return $r * 0.299 + $g * 0.587 + $b * 0.114; } for ($y = 0; $y < $destH; $y++) { for ($x = 0; $x < $destW; $x++) { $rgb = imagecolorat($dst, $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; //This is where we actually use yiq to modify our rbg values, and then convert them to our grayscale palette $gs = yiq($r, $g, $b); imagesetpixel($dst, $x, $y, $palette[$gs]); } } } if (isset($opts['rotation']) && !empty($opts['rotation'])) { $dst = imagerotate($dst, (double) $opts['rotation'], 0); } try { /* Filters : IMG_FILTER_GRAYSCALE: Converts the image into grayscale. IMG_FILTER_BRIGHTNESS: Changes the brightness of the image. Use arg1 to set the level of brightness. IMG_FILTER_CONTRAST: Changes the contrast of the image. Use arg1 to set the level of contrast. IMG_FILTER_COLORIZE: Like IMG_FILTER_GRAYSCALE, except you can specify the color. Use arg1, arg2 and arg3 in the form of red, blue, green and arg4 for the alpha channel. The range for each color is 0 to 255. IMG_FILTER_EDGEDETECT: Uses edge detection to highlight the edges in the image. IMG_FILTER_EMBOSS: Embosses the image. IMG_FILTER_GAUSSIAN_BLUR: Blurs the image using the Gaussian method. IMG_FILTER_SELECTIVE_BLUR: Blurs the image. IMG_FILTER_MEAN_REMOVAL: Uses mean removal to achieve a "sketchy" effect. IMG_FILTER_SMOOTH: Makes the image smoother. Use arg1 to set the level of smoothness. IMG_FILTER_PIXELATE: Applies pixelation effect to the image, use arg1 to set the block size and arg2 to set the pixelation effect mode. */ if (isset($opts['IMG_FILTER_NEGATE']) && !empty($opts['IMG_FILTER_NEGATE'])) { imagefilter($dst, IMG_FILTER_NEGATE); } if (isset($opts['IMG_FILTER_GRAYSCALE']) && !empty($opts['IMG_FILTER_GRAYSCALE'])) { imagefilter($dst, IMG_FILTER_GRAYSCALE); } if (isset($opts['IMG_FILTER_BRIGHTNESS']) && !empty($opts['IMG_FILTER_BRIGHTNESS'])) { imagefilter($dst, IMG_FILTER_BRIGHTNESS, intval($opts['IMG_FILTER_BRIGHTNESS'])); } if (isset($opts['IMG_FILTER_CONTRAST']) && !empty($opts['IMG_FILTER_CONTRAST'])) { imagefilter($dst, IMG_FILTER_CONTRAST, intval($opts['IMG_FILTER_CONTRAST'])); } if (isset($opts['IMG_FILTER_COLORIZE']) && !empty($opts['IMG_FILTER_COLORIZE'])) { if (strlen($opts['IMG_FILTER_COLORIZE']) == 12) { $arg1 = intval(substr($opts['IMG_FILTER_COLORIZE'], 0, 3)); $arg2 = intval(substr($opts['IMG_FILTER_COLORIZE'], 3, 3)); $arg3 = intval(substr($opts['IMG_FILTER_COLORIZE'], 6, 3)); $arg4 = intval(substr($opts['IMG_FILTER_COLORIZE'], 9, 3)); imagefilter($dst, IMG_FILTER_COLORIZE, $arg1, $arg2, $arg3, $arg4); } } if (isset($opts['IMG_FILTER_EDGEDETECT']) && !empty($opts['IMG_FILTER_EDGEDETECT'])) { imagefilter($dst, IMG_FILTER_EDGEDETECT); } if (isset($opts['IMG_FILTER_EMBOSS']) && !empty($opts['IMG_FILTER_EMBOSS'])) { imagefilter($dst, IMG_FILTER_EMBOSS); } if (isset($opts['IMG_FILTER_GAUSSIAN_BLUR']) && !empty($opts['IMG_FILTER_GAUSSIAN_BLUR'])) { imagefilter($dst, IMG_FILTER_GAUSSIAN_BLUR); } //: Reverses all colors of the image. if (isset($opts['IMG_FILTER_SELECTIVE_BLUR']) && !empty($opts['IMG_FILTER_SELECTIVE_BLUR'])) { imagefilter($dst, IMG_FILTER_SELECTIVE_BLUR); } //: Reverses all colors of the image. if (isset($opts['IMG_FILTER_MEAN_REMOVAL']) && !empty($opts['IMG_FILTER_MEAN_REMOVAL'])) { imagefilter($dst, IMG_FILTER_MEAN_REMOVAL); } //: Reverses all colors of the image. if (isset($opts['IMG_FILTER_SMOOTH']) && !empty($opts['IMG_FILTER_SMOOTH'])) { imagefilter($dst, IMG_FILTER_SMOOTH, intval($opts['IMG_FILTER_SMOOTH'])); } //: Reverses all colors of the image. if (isset($opts['IMG_FILTER_PIXELATE']) && !empty($opts['IMG_FILTER_PIXELATE'])) { if (strlen($opts['IMG_FILTER_PIXELATE']) > 3) { $arg1 = intval(substr($opts['IMG_FILTER_PIXELATE'], 0, 3)); $arg2 = $opts['IMG_FILTER_PIXELATE'] == true; } else { $arg1 = intval($opts['IMG_FILTER_PIXELATE']); $arg2 = false; } imagefilter($dst, IMG_FILTER_PIXELATE, $arg1, $arg2); } //: Reverses all colors of the image. } catch (Exception $e) { var_dump($e); } ob_start(); $outputFunction($dst, null, $quality); $this->_data = ob_get_contents(); ob_end_clean(); imagedestroy($src); imagedestroy($dst); //The following depends on Imagick //$this->_image is the Imagick Object; add calls to the different native functions as needed, it is returned as $this->_data at the end. if (class_exists('Imagick') && (isset($opts['cropx']) || isset($opts['cropy']) || isset($opts['brightness']) || isset($opts['saturation']) || isset($opts['hue']) || isset($opts['contrast']) || isset($opts['composite']))) { IMagick::setResourceLimit(imagick::RESOURCETYPE_MEMORY, 512); $this->_image = new Imagick(); $this->_image->readImageBlob($this->_data); //For image cropping if (isset($opts['cropx']) && !empty($opts['cropx'])) { if (!isset($opts['cropy']) || empty($opts['cropy'])) { $opts['cropy'] = 0; } if (isset($opts['lencropx']) && !empty($opts['lencropx'])) { $maxwidth = $opts['lencropx']; } else { $maxwidth = $config['maxLengthCropX']; } if (isset($opts['lencropy']) && !empty($opts['lencropy'])) { $maxheight = $opts['lencropy']; } else { $maxheight = $config['maxLengthCropY']; } $this->_image->cropImage($maxwidth, $maxheight, $opts['cropx'], $opts['cropy']); } else { if (isset($opts['cropy']) && !empty($opts['cropy'])) { if (!isset($opts['cropx']) || empty($opts['cropx'])) { $opts['cropx'] = 0; } if (isset($opts['lencropx']) && !empty($opts['lencropx'])) { $maxwidth = $opts['lencropx']; } else { $maxwidth = 410; } if (isset($opts['lencropy']) && !empty($opts['lencropy'])) { $maxheight = $opts['lencropy']; } else { $maxheight = 275; } $this->_image->cropImage($maxwidth, $maxheight, $opts['cropx'], $opts['cropy']); } } //Modulate: 100 is the norm if (isset($opts['brightness']) && !empty($opts['brightness'])) { $this->_image->modulateImage($opts['brightness'], 100, 100); } if (isset($opts['saturation']) && !empty($opts['saturation'])) { $this->_image->modulateImage(100, $opts['saturation'], 100); } if (isset($opts['hue']) && !empty($opts['hue'])) { $this->_image->modulateImage(100, 100, $opts['hue']); } if (isset($opts['contrast']) && !empty($opts['contrast'])) { $this->_image->contrastImage($opts['contrast']); } //To blend 2 images if (isset($opts['composite']) && !empty($opts['composite'])) { $over = new Imagick($opts['composite']); $d = $this->_image->getImageGeometry(); $w = $d['width']; $h = $d['height']; $over->thumbnailImage($w, $h); $this->_image->compositeImage($over, imagick::COMPOSITE_DEFAULT, 0, 0); $over->clear(); $over->destroy(); } $this->_data = $this->_image->getImageBlob(); $this->_image->clear(); $this->_image->destroy(); } if ($config['cache']) { $this->saveCache($opts); } return $this->_data; }
/** * Generates a portion of an ImageMagick convert command to apply an alpha mask * * Note: More accurate values for radii used to generate the LASCO C2 & C3 alpha masks: * rocc_outer = 7.7; // (.9625 * orig) * rocc_inner = 2.415; // (1.05 * orig) * * LASCO C2 Image Scale * $lascoC2Scale = 11.9; * * Solar radius in arcseconds, source: Djafer, Thuillier and Sofia (2008) * $rsunArcSeconds = 959.705; * $rsun = $rsunArcSeconds / $lascoC2Scale; * = 80.647 // Previously, used hard-coded value of 80.814221 * * Generating the alpha masks: * $rocc_inner = 2.415; * $rocc_outer = 7.7; * * // convert to pixels * $radius_inner = $rocc_inner * $rsun; * $radius_outer = $rocc_outer * $rsun; * $innerCircleY = $crpix2 + $radius_inner; * $outerCircleY = $crpix2 + $radius_outer; * * exec("convert -size 1024x1024 xc:black -fill white -draw \"circle $crpix1,$crpix2 $crpix1,$outerCircleY\" * -fill black -draw \"circle $crpix1,$crpix2 $crpix1,$innerCircleY\" +antialias LASCO_C2_Mask.png") * * Masks have been pregenerated and stored in order to improve performance. * * Note on offsets: * * The original CRPIX1 and CRPIX2 values used to determine the location of the center of the sun in the image * are specified with respect to a bottom-left corner origin. The values passed in to this method from the tile * request, however, specify the offset with respect to a top-left corner origin. This simply makes things * a bit easier since ImageMagick also treats images as having a top-left corner origin. * * Region of interest: * * The region of interest (ROI) below is specified at the original JP2 image scale. * * @param object $imagickImage an initialized Imagick object * * @return void */ protected function setAlphaChannel(&$imagickImage) { $maskWidth = 1040; $maskHeight = 1040; $mask = HV_ROOT_DIR . '/resources/images/alpha-masks/LASCO_' . $this->uiLabels[2]['name'] . '_Mask.png'; if ($this->reduce > 0) { $maskScaleFactor = 1 / pow(2, $this->reduce); } else { $maskScaleFactor = 1; } $maskTopLeftX = ($this->imageSubRegion['left'] + ($maskWidth - $this->jp2->getWidth()) / 2 - $this->offsetX) * $maskScaleFactor; $maskTopLeftY = ($this->imageSubRegion['top'] + ($maskHeight - $this->jp2->getHeight()) / 2 - $this->offsetY) * $maskScaleFactor; $width = $this->subfieldWidth * $maskScaleFactor; $height = $this->subfieldHeight * $maskScaleFactor; // $maskTopLeft coordinates cannot be negative when cropping, so if they are, adjust the width and height // by the negative offset and crop with zero offsets. Then put the image on the properly-sized image // and offset it correctly. $cropWidth = round($width + min($maskTopLeftX, 0)); $cropHeight = round($height + min($maskTopLeftY, 0)); $mask = new IMagick($mask); // Imagick floors pixel values but they need to be rounded up or down. // Rounding cannot be done in the previous lines of code because some addition needs to take place first. $maskTopLeftX = round($maskTopLeftX); $maskTopLeftY = round($maskTopLeftY); $width = round($width); $height = round($height); $mask->scaleImage($maskWidth * $maskScaleFactor, $maskHeight * $maskScaleFactor); $mask->cropImage($cropWidth, $cropHeight, max($maskTopLeftX, 0), max($maskTopLeftY, 0)); $mask->resetImagePage($width . 'x' . $height . '+0+0'); $mask->setImageBackgroundColor('black'); $mask->extentImage($width, $height, $width - $cropWidth, $height - $cropHeight); $imagickImage->setImageExtent($width, $height); $imagickImage->compositeImage($mask, IMagick::COMPOSITE_COPYOPACITY, 0, 0); if ($this->options['opacity'] < 100) { $mask->negateImage(true); $imagickImage->setImageClipMask($mask); $imagickImage->setImageOpacity($this->options['opacity'] / 100); } $mask->destroy(); }
<?php ignore_user_abort(true); set_time_limit(0); // pixel cache max size IMagick::setResourceLimit(imagick::RESOURCETYPE_MEMORY, 256); // maximum amount of memory map to allocate for the pixel cache IMagick::setResourceLimit(imagick::RESOURCETYPE_MAP, 256); $mid = $_REQUEST['mid']; mkdir("../upload/"); $fname = md5($file_name[1] . date() . rand(0, 100000)) . ".jpg"; while (file_exists("../../magazine/" . $mid . "/" . $fname)) { $fname = md5($file_name[1] . date() . rand(0, 100000)) . ".jpg"; } move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $fname); $img = new imagick(); $img->setResolution(500, 500); $img->readimage("../upload/" . $fname); $img->scaleImage(1000, 0); $img->writeImage("../../magazine/" . $mid . "/" . $fname); $img->scaleImage(200, 0); $img->writeImage("../../magazine/" . $mid . "/small/" . $fname); include "conn.php"; $sql = "SELECT `magazine`.`size` FROM `magazine` WHERE `magazine`.`id`=" . $mid . ""; $result = mysql_query($sql, $conn); $row = mysql_fetch_array($result); $sql = "INSERT INTO `pages` (`magazine`, `name`, `position`) VALUES (" . $mid . ", '" . $fname . "', '" . $row[0] . "');"; mysql_query($sql, $conn); $sql = "UPDATE `magazine` SET size=size+1 WHERE `magazine`.`id`='" . $mid . "'"; mysql_query($sql, $conn); echo mysql_insert_id($conn);
<?php $width = intval($_GET['width']); $height = intval($_GET['height']); if (!(is_int($width) and is_int($height))) { exit($height); } $width = 1440; $height = 900; $image = new IMagick('media/images/menu.png'); $geo = $image->getImageGeometry(); $image->scaleimage(round($width * $geo['width'] / 1920), round($height * $geo['height'] / 1080)); $image->setImageFormat('png'); header('Content-Type: image/png'); exit($image);
public function __toString() { return $this->im->__toString(); }
public function editAction() { $types = $this->config->fa->upload_types->toArray(); $id = (int) $this->getParam('id'); if ($id !== 0) { // Edit existing record. // TODO: Reimplement administrator access. $record = Upload::getRepository()->findOneBy(array('id' => $id, 'user_id' => $this->user->id)); if (!$record instanceof Upload) { throw new \FA\Exception('Submission ID not found!'); } $edit_mode = true; $type = $record->submission_type; } else { // Create new submission. $type = $this->getParam('type'); // Show type selector if no type is specified. if (empty($type) || !isset($types[$type])) { $this->view->types = $types; return $this->view->pick('uploads/select'); } $edit_mode = false; $record = NULL; } $type_info = $types[$type]; $form_config = $this->current_module_config->forms->uploads_edit->toArray(); // Create mode changes if (!$edit_mode) { $form_config['groups']['files']['elements']['submission'][1]['required'] = true; unset($form_config['groups']['files']['elements']['submission'][1]['description']); unset($form_config['groups']['files']['elements']['rebuild_thumbnail']); } // Changes to the form based on submission type. if (isset($type_info['category'])) { $form_config['groups']['metadata']['elements']['category'][1]['default'] = $type_info['category']; } if ($type !== Upload::TYPE_IMAGE) { unset($form_config['groups']['files']['elements']['rebuild_thumbnail']); } $form_config['groups']['files']['elements']['submission'][1]['allowedTypes'] = $type_info['types']; // Create the form class. $form = new \FA\Form($form_config); // Populate the form (if available). if ($record instanceof Upload) { $form->setDefaults($record->toArray(TRUE, TRUE)); } // Handle form submission. if ($_POST && $this->request->hasFiles() && $form->isValid(array_merge($_POST, $_FILES))) { $data = $form->getValues(); if (!$record instanceof Upload) { $record = new Upload(); $record->upload_type = $type; $record->user = $this->user; $record->is_hidden = true; // Hide until properly populated. $record->save(); // Immediately save to generate IDs used in next steps. } $record->fromArray($data); // Begin file handling. \IMagick::setResourceLimit(\Imagick::RESOURCETYPE_MEMORY, 32); \IMagick::setResourceLimit(\Imagick::RESOURCETYPE_MAP, 32); $files = $form->getFiles($this->request); $imagine = new Imagine(); $submission_file = $files['submission'][0]; $thumbnail_file = null; $thumbnail_paths = array(); $preview_file = null; $preview_paths = array(); if ($submission_file) { $submission_paths = $record->generatePaths($submission_file->getName()); // Create the proper artwork directory if it doesn't exist. $submission_dir = dirname($submission_paths['full']['path']); @mkdir($submission_dir); if ($type == Upload::TYPE_IMAGE) { // Handle image uploads. $submission_image = $imagine->open($submission_file->getTempName()); $is_animated = count($submission_image->layers()) > 1; // So, it seems Imagine really loves to screw up GIFs, so lets avoid that if ($is_animated) { $dest_path = $submission_paths['full']['path']; // Copying this instead of moving due to the file being reused by preview/thumbnail copy($submission_file->getTempName(), $dest_path); } else { $submission_image->save($submission_paths['full']['path'], array('animated' => $is_animated)); } // Make this file the thumbnail if no other is specified. if (empty($files['thumbnail']) && (!$edit_mode || $data['rebuild_thumbnail'])) { $thumbnail_file = $submission_file; $thumbnail_paths = $submission_paths; } // Set up the preview parameters $preview_file = $submission_file; $preview_paths = $submission_paths; } else { // Handle non-images. Way simpler, right? $dest_path = $submission_paths['full']['path']; $submission_file->moveTo($dest_path); // Prevent the file from being deleted below. $submission_file = null; } $record->setFull($submission_paths['full']['base']); } // Use the thumbnail field if supplied. if (!empty($files['thumbnail'])) { $thumbnail_file = $files['thumbnail'][0]; $thumbnail_paths = $record->generatePaths($thumbnail_file->getName()); } // If we haven't set a preview image/path, then use the thumbnail if possible if (is_null($preview_file)) { $preview_file = $thumbnail_file; $preview_paths = $thumbnail_paths; } // Process either the uploaded thumbnail, or resize the original file to be our preview. if ($preview_file) { // Generate "small" size thumbnail. $preview_size = new Box(self::MAX_PREVIEW_SIZE, self::MAX_PREVIEW_SIZE); self::_saveAsJPG($imagine, $preview_file, $preview_paths['small']['path'], 90, $preview_size); $record->setSmall(self::_changeExtension($preview_paths['small']['base'], 'jpg')); } // Process either the uploaded thumbnail, or thumbnailize the original file. if ($thumbnail_file) { // Generate "thumb" size thumbnail. $thumbnail_size = new Box(self::MAX_THUMB_SIZE, self::MAX_THUMB_SIZE); self::_saveAsJPG($imagine, $thumbnail_file, $thumbnail_paths['thumbnail']['path'], 90, $thumbnail_size); $record->setThumbnail(self::_changeExtension($thumbnail_paths['thumbnail']['base'], 'jpg')); } // Delete the temp files (if not already moved). if ($submission_file) { @unlink($submission_file->getTempName()); } if ($thumbnail_file) { @unlink($thumbnail_file->getTempName()); } // Unhide the record that was hidden earlier. if (!$edit_mode) { $record->is_hidden = false; } $record->save(); $view_url = $this->url->get('view/' . $record->id); $view_link = 'You can <a href="' . $view_url . '" target="_blank_">view your submission\'s public page here</a>.'; if ($edit_mode) { $this->alert('<b>Submission Updated!</b><br>' . $view_link, 'green'); } else { $this->alert('<b>New Submission Uploaded!</b><br>' . $view_link, 'green'); } return $this->redirectFromHere(array('action' => 'index', 'id' => NULL, 'type' => NULL)); } // Render the main form. $this->view->type_info = $type_info; $this->view->form = $form; }
/** * Builds the requested subfield image. * * Normalizing request & native image scales: * * When comparing the requested or "desired" image scale for the subfield * image to the native or "actual" image scale of the source image, it is * convenient to create a variable called "desiredToActual" which * represents the ratio of the desired scale to the actual scale. * * There are three possible cases which may occur: * * 1) desiredToActual = 1 * * In this case the subfield requested is at the natural image * scale. No resizing is necessary. * * 2) desiredToActual < 1 * * The subfield requested is at a lower image scale (HIGHER * quality) than the source JP2. * * 3) desiredToActual > 1 * * The subfield requested is at a higher image scale (LOWER * quality) than the source JP2. * * @TODO: Normalize quality scale. * @TODO: Create a cleanup array with names of files to be wiped after * processing is complete? * @TODO: Move generation of intermediate file to separate method * * @return void */ protected function build() { /* * Need to extend the time limit that writeImage() can use so it * doesn't throw fatal errors when movie frames are being made. * It seems that even if this particular instance of writeImage * doesn't take the full time frame, if several instances of it are * running PHP will complain. */ set_time_limit(600); try { // Choose extension to convert source image to if ($this->options['palettedJP2']) { $extension = '.bmp'; } else { $extension = '.pgm'; } $input = substr($this->outputFile, 0, -4) . rand() . $extension; // Extract region (PGM) $this->jp2->extractRegion($input, $this->imageSubRegion, $this->reduce); // Apply colormap if needed if (!$this->options['palettedJP2']) { // Convert to GD-readable format $grayscale = new IMagick($input); if (isset($this->options['verifyGrayscale']) && $this->options['verifyGrayscale'] && $grayscale->getImageType() != imagick::IMGTYPE_GRAYSCALE) { $this->colorTable = false; } $grayscale->setImageFormat('PNG'); $grayscale->setImageDepth(8); // Fastest PNG compression setting $grayscale->setImageCompressionQuality(10); // Assume that no color table is needed $coloredImage = $grayscale; // Apply color table if one exists if ($this->colorTable) { $clut = new IMagick($this->colorTable); $coloredImage->clutImage($clut); } } else { $coloredImage = new IMagick($input); } // Set alpha channel for images with transparent components $this->setAlphaChannel($coloredImage); // Apply compression and interlacing $this->compressImage($coloredImage); // Resize extracted image to correct size before padding. $rescaleBlurFactor = 0.6; $coloredImage->resizeImage(round($this->subfieldRelWidth), round($this->subfieldRelHeight), $this->imageOptions['rescale'], $rescaleBlurFactor); $coloredImage->setImageBackgroundColor('transparent'); // Places the current image on a larger field of black if the final // image is larger than this one $imagickVersion = $coloredImage->getVersion(); if ($imagickVersion['versionNumber'] > IMAGE_MAGICK_662_VERSION_NUM) { // ImageMagick 6.6.2-6 and higher // Problematic change occurred in revision 6.6.4-2 // See: http://www.imagemagick.org/script/changelog.php $coloredImage->extentImage($this->padding['width'], $this->padding['height'], $this->padding['offsetX'], $this->padding['offsetY']); } else { // Imagick 3.0 and lower $coloredImage->extentImage($this->padding['width'], $this->padding['height'], -$this->padding['offsetX'], -$this->padding['offsetY']); } $this->image = $coloredImage; // Check for PGM before deleting just in case another process // already removed it if (@file_exists($input)) { @unlink($input); } } catch (Exception $e) { // Clean-up intermediate files $this->_abort($this->outputFile); throw $e; } }
public function RenderImage($strPath = null) { switch ($this->Mode) { case NavBarImageMode::Standard: case NavBarImageMode::Hover: // Setup Colors if ($this->Mode == NavBarImageMode::Standard) { $objTextColor = new ImagickPixel('#bbc5bb'); $objBackgroundColor = new ImagickPixel('#5c5c5c'); $objBackgroundColorHighlight = new ImagickPixel('#808080'); $objBackgroundColorHighlightLess = new ImagickPixel('#696969'); } else { $objTextColor = new ImagickPixel('#ffffff'); $objBackgroundColor = new ImagickPixel('#667066'); $objBackgroundColorHighlight = new ImagickPixel('#99a599'); $objBackgroundColorHighlightLess = new ImagickPixel('#778277'); } // Create Objects $this->objImage = new IMagick(); $this->objImage->NewImage($this->strWidth * $this->intQuality, $this->strHeight * $this->intQuality, $objBackgroundColor); $this->objDraw = new IMagickDraw(); // Draw Highlights $this->objDraw->setStrokeColor($objBackgroundColorHighlight); $this->DrawHorizontalLine(0, $this->strWidth, 0); $this->DrawVerticalLine(0, 0, $this->strHeight); $this->objDraw->setStrokeColor($objBackgroundColorHighlightLess); $this->DrawHorizontalLine(1, $this->strWidth, 1); $this->DrawVerticalLine(1, 1, $this->strHeight); // Overlay Shade $objNewImage = new IMagick(__DOCROOT__ . '/images/mask.png'); $objNewImage->ResizeImage($this->strWidth * $this->intQuality, $this->strHeight * $this->intQuality, IMagick::FILTER_GAUSSIAN, 0.7); $this->objImage->CompositeImage($objNewImage, Imagick::COMPOSITE_MULTIPLY, 0, 0); // Draw Text $this->objDraw->setTextAntiAlias(false); $this->objDraw->setStrokeColor($objTextColor); $this->objDraw->setFillColor($objTextColor); $this->objDraw->SetFont(__QCODO__ . '/fonts/Formata-Medium.pfb'); $this->SetFontSize(14); $this->DrawTextCenterBottom($this->Text, 4); // Scale Down $this->objImage->ResizeImage($this->strWidth, $this->strHeight, Imagick::FILTER_GAUSSIAN, 0.7); break; default: $objBackgroundColor = new ImagickPixel('#335533'); $objBackgroundColorHighlight = new ImagickPixel('#112211'); $objBackgroundColorHighlightLess = new ImagickPixel('#224422'); $objTextColor = new ImagickPixel('#ffffee'); // Create Objects $this->objImage = new IMagick(); $this->objImage->NewImage($this->strWidth * $this->intQuality, $this->strHeight * $this->intQuality, $objBackgroundColor); $this->objDraw = new IMagickDraw(); // Draw Highlights $this->objDraw->setStrokeColor($objBackgroundColorHighlight); // $this->DrawHorizontalLine(0, $this->strWidth, 0); $this->DrawVerticalLine(0, 0, $this->strHeight); $this->objDraw->setStrokeColor($objBackgroundColorHighlightLess); // $this->DrawHorizontalLine(1, $this->strWidth, 1); $this->DrawVerticalLine(1, 0, $this->strHeight); // Draw Text $this->objDraw->setTextAntiAlias(false); $this->objDraw->setStrokeColor($objTextColor); $this->objDraw->setFillColor($objTextColor); $this->objDraw->SetFont(__QCODO__ . '/fonts/Formata-Medium.pfb'); $this->SetFontSize(14); $this->DrawTextCenterBottom($this->Text, 4); // Scale Down $this->objImage->ResizeImage($this->strWidth, $this->strHeight, Imagick::FILTER_GAUSSIAN, 0.7); break; } return $this->RenderImageMagickHelper($this->objImage, $strPath); }