private function getImage() { $image = imagecreatefromstring(file_get_contents($this->file['tmp_name'])); if ($this->currentExtension == 'jpg' || $this->currentExtension == 'jpeg') { $exif = exif_read_data($this->file['tmp_name']); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $image = imagerotate($image, 90, 0); break; case 3: $image = imagerotate($image, 180, 0); break; case 6: $image = imagerotate($image, -90, 0); break; } } } // Get new sizes $width = imagesx($image); $height = imagesy($image); //list($width, $height) = getimagesize($this->file['tmp_name']); list($newWidth, $newHeight) = $this->getScaledDimArray($image, 800); // Load $resizeImage = imagecreatetruecolor($newWidth, $newHeight); // Resize imagecopyresized($resizeImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); return $resizeImage; }
public function getImage($sourceFile = null) { if (!isset($sourceFile)) { $sourceFile = $this->BlankPath; } return imagecreatefromstring(file_get_contents($sourceFile)); }
public function action_thumb() { if (!preg_match('/^image\\/.*$/i', $this->attachment['mime'])) { $ext = File::ext_by_mime($this->attachment['mime']); if (file_exists(DOCROOT . 'img/icons/' . $ext . '-icon-128x128.png')) { $this->redirect('/img/icons/' . $ext . '-icon-128x128.png'); } else { $this->redirect('http://stdicon.com/' . $this->attachment['mime'] . '?size=96&default=http://stdicon.com/text'); } } if (!file_exists(DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb')) { if (!file_exists(DOCROOT . 'storage/' . $this->attachment['id'])) { $this->redirect('http://stdicon.com/' . $this->attachment['mime'] . '?size=96&default=http://stdicon.com/text'); } $data = file_get_contents(DOCROOT . 'storage/' . $this->attachment['id']); $image = imagecreatefromstring($data); $x = imagesx($image); $y = imagesy($image); $size = max($x, $y); $x = round($x / $size * 96); $y = round($y / $size * 96); $thumb = imagecreatetruecolor($x, $y); imagealphablending($thumb, false); imagesavealpha($thumb, true); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $x, $y, imagesx($image), imagesy($image)); imagepng($thumb, DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb', 9); } header('Content-type: image/png'); header('Content-disposition: filename="thumbnail.png"'); header('Content-length: ' . filesize(DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb')); readfile(DOCROOT . 'storage/' . $this->attachment['id'] . '.thumb'); die; }
function getimagesize_remote($image_url) { if (!($handle = @fopen($image_url, 'rb'))) { return 0; } $contents = ''; $count = 0; if ($handle) { do { $count += 1; $data = fread($handle, 8192); if (strlen($data) == 0) { break; } $contents .= $data; // Workaround for more speed: // For the size range usually the first bytes, it reads: // therefore only max. the first ~ 40 bytes // // } while(true); } while ($count <= 5); } else { return 0; } fclose($handle); if (!($im = imagecreatefromstring($contents))) { return 0; } $gis[0] = Imagesx($im); $gis[1] = Imagesy($im); imagedestroy($im); // array member 3 is used below to keep with current getimagesize standards $gis[3] = "width={$gis[0]} height={$gis[1]}"; return $gis; }
/** * Extracts the colour palette of the set image * * @return array * @throws Exception */ public function extractPalette() { if (is_null($this->image)) { throw new Exception('An image must be set before its palette can be extracted.'); } if (($size = getimagesize($this->image)) === false) { throw new Exception("Unable to get image size data"); } if (($img = imagecreatefromstring(file_get_contents($this->image))) === false) { throw new Exception("Unable to open image file"); } $colors = array(); for ($x = 0; $x < $size[0]; $x += $this->granularity) { for ($y = 0; $y < $size[1]; $y += $this->granularity) { $rgb = imagecolorsforindex($img, imagecolorat($img, $x, $y)); $red = round(round($rgb['red'] / 0x33) * 0x33); $green = round(round($rgb['green'] / 0x33) * 0x33); $blue = round(round($rgb['blue'] / 0x33) * 0x33); $thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue); if (array_key_exists($thisRGB, $colors)) { $colors[$thisRGB]++; } else { $colors[$thisRGB] = 1; } } } arsort($colors); return array_slice(array_keys($colors), 0, $this->totalColors); }
/** * Renders a scaled version of the image referenced by the provided filename, taken any (optional) manipulators into consideration. * @param String $sourceData The binary data of the original source image. * @param Array $scaleParams * @param Int $imageType One of the PHP image type constants, such as IMAGETYPE_JPEG * @return Array * ['resource'] The image file data string * ['mime'] Mime type of the generated cache file * ['timestamp'] Timestamp of the generated cache file **/ public function scale($sourceData, $scaleParams, $imageType) { $this->_setInputParams($scaleParams); $mem = new Garp_Util_Memory(); $mem->useHighMemory(); if (strlen($sourceData) == 0) { throw new Exception("This is an empty file!"); } if (!($source = imagecreatefromstring($sourceData))) { $finfo = new finfo(FILEINFO_MIME); $mime = $finfo->buffer($sourceData); throw new Exception("This source image could not be scaled. It's probably not a valid file type. Instead, this file is of the following type: " . $mime); } $this->_analyzeSourceImage($source, $imageType); $this->_addOmittedCanvasDimension(); if ($this->_isFilterDefined($scaleParams)) { Garp_Image_Filter::filter($source, $scaleParams['filter']); } if ($this->_isSourceEqualToTarget($scaleParams)) { $outputImage = $sourceData; } else { $canvas = $this->_createCanvasImage($imageType); $this->_projectSourceOnCanvas($source, $canvas); // Enable progressive jpegs imageinterlace($canvas, true); $outputImage = $this->_renderToImageData($canvas); imagedestroy($canvas); } $output = array('resource' => $outputImage, 'mime' => $this->params['mime'], 'timestamp' => time()); imagedestroy($source); return $output; }
/** * @return ZipInterface */ public function render() { $pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath(); if ($pathThumbnail) { // Size : 128x128 pixel // PNG : 8bit, non-interlaced with full alpha transparency $gdImage = imagecreatefromstring(file_get_contents($pathThumbnail)); if ($gdImage) { list($width, $height) = getimagesize($pathThumbnail); $gdRender = imagecreatetruecolor(128, 128); $colorBgAlpha = imagecolorallocatealpha($gdRender, 0, 0, 0, 127); imagecolortransparent($gdRender, $colorBgAlpha); imagefill($gdRender, 0, 0, $colorBgAlpha); imagecopyresampled($gdRender, $gdImage, 0, 0, 0, 0, 128, 128, $width, $height); imagetruecolortopalette($gdRender, false, 255); imagesavealpha($gdRender, true); ob_start(); imagepng($gdRender); $imageContents = ob_get_contents(); ob_end_clean(); imagedestroy($gdRender); imagedestroy($gdImage); $this->getZip()->addFromString('Thumbnails/thumbnail.png', $imageContents); } } return $this->getZip(); }
function resize($width, $height, $path, $i) { /* Get original image x y*/ list($w, $h) = getimagesize($_FILES['image']['tmp_name'][$i]); /* calculate new image size with ratio */ $ratio = max($width / $w, $height / $h); $h = ceil($height / $ratio); $x = ($w - $width / $ratio) / 2; $w = ceil($width / $ratio); /* new file name */ /* read binary data from image file */ $imgString = file_get_contents($_FILES['image']['tmp_name'][$i]); /* create image from string */ $image = imagecreatefromstring($imgString); $tmp = imagecreatetruecolor($width, $height); imagecopyresampled($tmp, $image, 0, 0, $x, 0, $width, $height, $w, $h); /* Save image */ switch ($_FILES['image']['type'][$i]) { case 'image/jpeg': imagejpeg($tmp, $path, 100); break; case 'image/png': imagepng($tmp, $path, 0); break; case 'image/gif': imagegif($tmp, $path); break; default: return false; break; } imagedestroy($image); imagedestroy($tmp); return true; }
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; } }
/** * Fit small image to specified bound * * @param string $src * @param string $dest * @param int $width * @param int $height * @return bool */ public function fit($src, $dest, $width, $height) { // Calculate $size = getimagesize($src); $ratio = max($width / $size[0], $height / $size[1]); $old_width = $size[0]; $old_height = $size[1]; $new_width = intval($old_width * $ratio); $new_height = intval($old_height * $ratio); // Resize @ini_set('memory_limit', apply_filters('image_memory_limit', WP_MAX_MEMORY_LIMIT)); $image = imagecreatefromstring(file_get_contents($src)); $new_image = wp_imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); if (IMAGETYPE_PNG == $size[2] && function_exists('imageistruecolor') && !imageistruecolor($image)) { imagetruecolortopalette($new_image, false, imagecolorstotal($image)); } // Destroy old image imagedestroy($image); // Save switch ($size[2]) { case IMAGETYPE_GIF: $result = imagegif($new_image, $dest); break; case IMAGETYPE_PNG: $result = imagepng($new_image, $dest); break; default: $result = imagejpeg($new_image, $dest); break; } imagedestroy($new_image); return $result; }
function get_notice_by_meta($name, $filename) { global $pmb_keyword_sep; global $pmb_type_audit; global $webdav_current_user_name, $webdav_current_user_id; \create_tableau_mimetype(); $mimetype = \trouve_mimetype($filename, extension_fichier($name)); //on commence avec la gymnatisque des métas... if ($mimetype == "application/epub+zip") { //pour les ebook, on gère ca directement ici ! $epub = new \epubData(realpath($filename)); $metas = $epub->metas; $img = imagecreatefromstring($epub->getCoverContent()); $file = tempnam(sys_get_temp_dir(), "vign"); imagepng($img, $file); $metas['thumbnail_content'] = file_get_contents($file); unlink($file); } else { $metas = \extract_metas(realpath($filename), $mimetype); } if ($this->config['metasMapper_class']) { $className = "Sabre\\PMB\\" . $this->config['metasMapper_class']; if (class_exists($className)) { $metasMapper = new $className($this->config, $metas, $mimetype, $name); } } if (!is_object($metasMapper)) { $metasMapper = new metasMapper($this->config, $metas, $mimetype, $name); } return $metasMapper->get_notice_id(); }
function adjustThumbnailToVideoRatio( $upload, $ratio ){ if(empty($ratio)) { $ratio = 16/9; } $data = file_get_contents( $upload->getTempPath() ); $src = imagecreatefromstring( $data ); $orgWidth = $upload->mFileProps['width']; $orgHeight = $upload->mFileProps['height']; $finalWidth = $upload->mFileProps['width']; $finalHeight = $finalWidth / $ratio; $dest = imagecreatetruecolor ( $finalWidth, $finalHeight ); imagecopy( $dest, $src, 0, 0, 0, ( $orgHeight - $finalHeight ) / 2 , $finalWidth, $finalHeight ); $sTmpPath = $upload->getTempPath(); switch ( $upload->mFileProps['minor_mime'] ) { case 'jpeg': imagejpeg( $dest, $sTmpPath ); break; case 'gif': imagegif ( $dest, $sTmpPath ); break; case 'png': imagepng ( $dest, $sTmpPath ); break; } imagedestroy( $src ); imagedestroy( $dest ); }
function data_uri($mime) { imagepng(imagecreatefromstring(file_get_contents($_FILES["file"]["tmp_name"])), "scanned.png"); $contents = file_get_contents("scanned.png"); $base64 = base64_encode($contents); return 'data:' . $mime . ';base64,' . $base64; }
function createImage($name, $filename, $new_w, $new_h) { $system2 = explode('.', strtolower(basename($filename))); $system2[1] = $system2[1]; $src_img = imagecreatefromstring(readFileData($name)); $old_w = imageSX($src_img); $old_h = imageSY($src_img); $thumb_w = $new_w; $thumb_h = $new_h; if ($new_w > $old_w) { $thumb_w = $old_w; $thumb_h = $thumb_w / $old_w * $old_h; } else { $thumb_w = $new_w; $thumb_h = $thumb_w / $old_w * $old_h; } if ($thumb_h > $new_h) { $thumb_h = $new_h; $thumb_w = $thumb_h / $old_h * $old_w; } $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $transparent); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_w, $old_h); if (preg_match("/png/", $system2[1])) { imagepng($dst_img, $filename); } else { imagejpeg($dst_img, $filename, 90); } imagedestroy($dst_img); imagedestroy($src_img); }
public function logo() { Vendor("phpqrcode.phpqrcode"); $QRcode = new \QRcode(); $path = "data/rq/"; $value = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?token=' . session('token'); $fileName = $path . session('token') . '_emall.png'; $QR_Logo = $path . session('token') . '_emall_Logo.png'; $errorCorrectionLevel = 'H'; $matrixPointSize = 10; $QRcode->png($value, $fileName, $errorCorrectionLevel, $matrixPointSize, 2); $logo = $path . 'weixinlogo.jpg'; $QR = $fileName; if ($logo !== FALSE) { $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); $QR_height = imagesy($QR); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $logo_qr_width = $QR_width / 5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($QR_width - $logo_qr_width) / 2; imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); } imagepng($QR, $QR_Logo); $this->assign('QR_Logo', $QR_Logo); $this->display(); if (IS_AJAX) { $response = $this->fetch(); $this->ajaxReturn(1, '', $response); } }
/** * @desc ������� ������ ����������� * @return */ function outputPreview($szContent, $szMime) { $source = imagecreatefromstring($szContent); $nSourceHeight = imagesy($source); $nSourceWidth = imagesx($source); // �������� ������ � ������ if (DAO_IMAGE_THUMBNAIL_X == 0) { $szHeight = DAO_IMAGE_THUMBNAIL_Y; $szWidth = intval($nSourceWidth * DAO_IMAGE_THUMBNAIL_Y / $nSourceHeight); } elseif (DAO_IMAGE_THUMBNAIL_Y == 0) { $szWidth = DAO_IMAGE_THUMBNAIL_X; $szHeight = intval($nSourceHeight * DAO_IMAGE_THUMBNAIL_X / $nSourceWidth); } else { $szWidth = DAO_IMAGE_THUMBNAIL_X; $szHeight = DAO_IMAGE_THUMBNAIL_Y; } $thumb = imagecreatetruecolor($szWidth, $szHeight); imagecopyresized($thumb, $source, 0, 0, 0, 0, $szWidth, $szHeight, $nSourceWidth, $nSourceHeight); switch ($szMime) { case 'image/jpeg': imagejpeg($thumb); break; case 'image/png': imagepng($thumb); break; case 'image/gif': imagegif($thumb); break; default: imagejpeg($thumb); } }
function creaMapa($usuario, $img, $pantalla, $nombre, $nFil, $nCol) { $nombreComp = dirname(__DIR__) . "/../img/mapasUsuarios/{$nombre}.png"; //GUARDO UN FICHERO .PNG CON LA IMAGEN DE LA PANTALLA //Creo una imagen en memoria a partir de la cadena en base64:pacman/autogenerados $im = imagecreatefromstring($img); if ($im !== false) { header('Content-Type: image/png'); imagepng($im); //imagedestroy($im); } else { echo 'An error occurred.'; } //Creo el fichero para almacenar la imagen creada en memoria $ancho = 10 * $nCol; $alto = 10 * $nFil; $nuevaImg = imagecreatetruecolor($ancho, $alto); imagecopy($nuevaImg, $im, 0, 0, 0, 0, $ancho, $alto); imagepng($nuevaImg, $nombreComp); //El directorio esta en $nombreComp imagedestroy($nuevaImg); imagedestroy($im); //LLAMO A CONSULTAS PARA HACER LA INSERCION EN BBDD include_once dirname(__DIR__) . "/dao/consultas.php"; $chulta = metePantalla($pantalla, $nombre, $usuario, $nFil, $nCol); return $chulta; }
public function load_file($file) { $ctx = stream_context_create(array('http' => array('timeout' => 5))); $data = file_get_contents($file, false, $ctx); $this->image = \imagecreatefromstring($data); $this->file = $file; }
public function createfromstring($string) { $this->res = imagecreatefromstring($string); $this->sX(); $this->sY(); $this->init(); }
function resize_image($blob, $w, $h, $crop = false) { $src = imagecreatefromstring($blob); $width = imagesx($src); $height = imagesy($src); $r = $width / $height; if ($crop) { if ($w / $h < $r) { $newwidth = $h * $r; $newheight = $h; } else { $newheight = $w / $r; $newwidth = $w; } } else { if ($w / $h > $r) { $newwidth = $h * $r; $newheight = $h; } else { $newheight = $w / $r; $newwidth = $w; } } $dst = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); if ($crop) { $thumb = imagecreatetruecolor($w, $h); imagecopyresampled($thumb, $dst, 0, 0, ($newwidth - $w) / 2, ($newheight - $h) / 2, $w, $h, $w, $h); } $output = isset($thumb) ? $thumb : $dst; imagejpeg($output, '', 90); imagedestroy($dst); imagedestroy($src); return true; }
function resize($width, $height) { list($w, $h) = getimagesize($_FILES['image']['tmp_name']); $ratio = max($width / $w, $height / $h); $h = ceil($height / $ratio); $x = ($w - $width / $ratio) / 2; $w = ceil($width / $ratio); $path = 'photos/' . $width . 'x' . $height . '_' . $_FILES['image']['name']; $imgString = file_get_contents($_FILES['image']['tmp_name']); $image = imagecreatefromstring($imgString); $tmp = imagecreatetruecolor($width, $height); imagecopyresampled($tmp, $image, 0, 0, $x, 0, $width, $height, $w, $h); /* Save image */ switch ($_FILES['image']['type']) { case 'image/jpeg': imagejpeg($tmp, $path, 100); break; case 'image/png': imagepng($tmp, $path, 0); break; case 'image/gif': imagegif($tmp, $path); break; default: exit; break; } return $path; /* cleanup memory */ imagedestroy($image); imagedestroy($tmp); }
public function __construct($filename = null, array $options = array(), $binary = false, $type = null) { $this->filename = $filename; $this->remote = false; $this->binary = (bool) $binary; $this->assertFileAvaiable(); $this->detectFormat($type); if ($this->binary) { $this->oldImage = @imagecreatefromstring($this->filename); } else { switch ($this->format) { case self::TYPE_PNG: $this->oldImage = @imagecreatefrompng($this->filename); break; case self::TYPE_JPEG: $this->oldImage = @imagecreatefromjpeg($this->filename); break; case self::TYPE_GIF: $this->oldImage = @imagecreatefromgif($this->filename); break; } } if (!$this->oldImage) { $error = error_get_last(); throw new \InvalidArgumentException('create image with given resource failed' . ($error ? ' with error ' . $error['message'] : '')); } $this->currentDimensions = array('width' => imagesx($this->oldImage), 'height' => imagesy($this->oldImage)); $this->setOptions($options); }
public static function createImg($content, $qrc_level = 'H', $qrc_size = 10, $logo = FALSE, $savePath = null) { include_once 'phpqrcode.php'; // if($savePath) $QR = QRcode::png($content, $savePath, $qrc_level, $qrc_size, 2); if ($logo !== FALSE) { $QR = imagecreatefromstring(file_get_contents($savePath)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); // 二维码图片宽度 $QR_height = imagesy($QR); // 二维码图片高度 $logo_width = imagesx($logo); // logo图片宽度 $logo_height = imagesy($logo); // logo图片高度 $logo_qr_width = $QR_width / 5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($QR_width - $logo_qr_width) / 2; // 重新组合图片并调整大小 imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); } return $QR; }
public function load($path, $extension = null, $content = null) { global $F; $this->destroy(); $this->path = $path; if (is_null($extension)) { $extension = File::extension($path); } switch ($extension) { default: case "jpg": $this->resourceID = @imagecreatefromjpeg($path); break; case "gif": $this->resourceID = @imagecreatefromgif($path); break; case "png": $this->resourceID = @imagecreatefrompng($path); imagesavealpha($this->resourceID, true); break; case Image::DATA: $this->resourceID = @imagecreatefromstring($content); break; } if ($this->resourceID) { $this->width = imagesx($this->resourceID); $this->height = imagesy($this->resourceID); return true; } else { return false; } }
/** * Method draws a collage from friends avatars. * * @param $x * @param $y * @return resource * @throws \Exception */ public function drawCollage($x, $y) { $username = '******'; $friends = $this->getFriendsList($username); $posX = 0; $posY = 0; if (!isset($x) && !isset($y)) { throw new \Exception("height and width must be set!"); } $collage = imagecreatetruecolor($x, $y); while ($posY <= $y) { foreach ($friends['users'] as $user) { $image = imagecreatefromstring(file_get_contents($user['profile_image_url'])); imagecopymerge($collage, $image, $posX, $posY, 5, 5, 50, 50, 100); $posX += 50; if ($posX >= $x) { $posY += 50; $posX = 0; } if ($posX >= $x && $posY >= $y) { break; } } } return $collage; }
public function filter($value) { if (!file_exists($value)) { throw new Zend_Filter_Exception('Image does not exist: ' . $value); } $image = imagecreatefromstring(file_get_contents($value)); if (false === $image) { throw new Zend_Filter_Exception('Can\'t load image: ' . $value); } // find ratio to scale down to // TODO: pass 600 as parameter in the future $origWidth = imagesx($image); $origHeight = imagesy($image); $ratio = max($origWidth, $origHeight) / 600; if ($ratio > 1) { // img too big! create a scaled down image $newWidth = round($origWidth / $ratio); $newHeight = round($origHeight / $ratio); $resized = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight); // determine type and store to disk $explodeResult = explode(".", $value); $type = strtolower($explodeResult[count($explodeResult) - 1]); $writeFunc = 'image' . $type; if ($type == 'jpeg' || $type == 'jpg') { imagejpeg($resized, $value, 100); } else { $writeFunc($resized, $value); } } return $value; }
public static function fromBinary($binary) { $handle = imagecreatefromstring($binary); $whiteColor = imagecolorresolve($handle, 0xff, 0xff, 0xff); $blackColor = imagecolorresolve($handle, 0x0, 0x0, 0x0); return new self($handle, $whiteColor, $blackColor); }
/** * Output binary image from base-64 encoded data. * * @deprecated 1.5.1 * * @param string $imageData Base-64 encoded image data (via $_POST) */ public static function outputBinaryImage() { Piwik::checkUserHasSomeViewAccess(); $rawData = Piwik_Common::getRequestVar('imageData', '', 'string', $_POST); // returns false if any illegal characters in input $data = base64_decode($rawData); if ($data !== false) { // check for PNG header if (Piwik_Common::substr($data, 0, 8) === "‰PNG\r\n\n") { header('Content-Type: image/png'); // more robust validation (if available) if (function_exists('imagecreatefromstring')) { // validate image data $imgResource = @imagecreatefromstring($data); if ($imgResource !== false) { // output image and clean-up imagepng($imgResource); imagedestroy($imgResource); exit; } } else { echo $data; exit; } } } Piwik::setHttpStatus('400 Bad Request'); exit; }
/** * Create QRCODE 生成二维码的方法 * * @return false :该文件存在; true:生成二维码成功。 */ public function createQr() { if ($this->data) { if ($this->fileName !== false && file_exists($this->fileName)) { return false; } QRcode::png($this->data, $this->fileName, $this->ecc, $this->size); if ($this->logo != null) { $QR = $this->fileName; $dd = file_get_contents($QR); $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($this->logo)); $QR_width = imagesx($QR); $QR_height = imagesy($QR); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $logo_qr_width = $QR_width / 5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($QR_width - $logo_qr_width) / 2; imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); imagepng($QR, $this->fileName); } return true; } }
public function store_codeOp() { if ($_GET['text']) { $text = $_GET['text']; $size = '6'; $level = 'H'; $logo = BASE_RESOURCE_PATH . DS . '/logo_2.png'; $padding = '2'; $path = BASE_RESOURCE_PATH . DS . 'phpqrcode'; $QR = $path . 'qrcode.png'; require_once BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'phpqrcode.php'; QRcode::png($text, $QR, $level, $size, $padding); if ($logo !== false) { $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); $QR_height = imagesy($QR); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $logo_qr_width = $QR_width / 5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($QR_width - $logo_qr_width) / 2; imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); } header("Content-Type:image/jpg"); imagepng($QR); } else { output_error('参数错误00023'); } }