当前位置: 首页>>代码示例>>PHP>>正文


PHP imagecreatefromstring函数代码示例

本文整理汇总了PHP中imagecreatefromstring函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecreatefromstring函数的具体用法?PHP imagecreatefromstring怎么用?PHP imagecreatefromstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了imagecreatefromstring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getImage

 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;
 }
开发者ID:ambujaacool,项目名称:MyApp,代码行数:30,代码来源:ImageUpload.php

示例2: getImage

 public function getImage($sourceFile = null)
 {
     if (!isset($sourceFile)) {
         $sourceFile = $this->BlankPath;
     }
     return imagecreatefromstring(file_get_contents($sourceFile));
 }
开发者ID:nbey,项目名称:Emergence-Skeleton,代码行数:7,代码来源:AudioMedia.class.php

示例3: action_thumb

 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;
 }
开发者ID:Alex-AG,项目名称:exeltek-po,代码行数:33,代码来源:Download.php

示例4: getimagesize_remote

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;
}
开发者ID:startrekfinalfrontier,项目名称:UI,代码行数:35,代码来源:images.php

示例5: extractPalette

 /**
  * 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);
 }
开发者ID:bensquire,项目名称:php-color-extractor,代码行数:35,代码来源:PHPColorExtractor.php

示例6: scale

 /**
  * 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;
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:42,代码来源:Scaler.php

示例7: render

 /**
  * @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();
 }
开发者ID:phpoffice,项目名称:phppowerpoint,代码行数:30,代码来源:ThumbnailsThumbnail.php

示例8: resize

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;
}
开发者ID:phanduong2211,项目名称:phukienthoitranggiare,代码行数:35,代码来源:upload.blade.php

示例9: __construct

    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;
        }
    }
开发者ID:rvaliev,项目名称:php-qrcode-detector-decoder,代码行数:33,代码来源:QrReader.php

示例10: fit

 /**
  * 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;
 }
开发者ID:hametuha,项目名称:wpametu,代码行数:43,代码来源:Image.php

示例11: get_notice_by_meta

 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();
 }
开发者ID:noble82,项目名称:proyectos-ULS,代码行数:31,代码来源:Collection.php

示例12: adjustThumbnailToVideoRatio

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 );

}
开发者ID:schwarer2006,项目名称:wikia,代码行数:27,代码来源:videoMigrateData.php

示例13: data_uri

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;
}
开发者ID:behroozam,项目名称:OrthancContributed,代码行数:7,代码来源:createDicom.php

示例14: createImage

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);
}
开发者ID:qichangjun,项目名称:HTMLLearn,代码行数:34,代码来源:upload.php

示例15: logo

 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);
     }
 }
开发者ID:yaks,项目名称:weixinshop,代码行数:34,代码来源:templetAction.class.php


注:本文中的imagecreatefromstring函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。