Example #1
2
File: Stream.php Project: gtyd/jira
 public function making($dst_w, $dst_h)
 {
     $thumb_img = imagecreatetruecolor($dst_w, $dst_h);
     imagecopyresampled($thumb_img, $this->image, 0, 0, 0, 0, $dst_w, $dst_h, $this->width, $this->height);
     ob_start();
     switch ($this->_mimetype) {
         case "gd2":
             imagegd2($thumb_img, null, 100);
             break;
         case "gd":
             imagegd($thumb_img, null, 100);
             break;
         case "gif":
             imagegif($thumb_img, null, 100);
             break;
         case "jpeg":
             imagejpeg($thumb_img, null, 100);
             break;
         case "jpg":
             imagejpeg($thumb_img, null, 100);
             break;
         case "png":
             imagepng($thumb_img, null, 9);
             break;
         case "webp":
             imagewebp($thumb_img, null, 100);
             break;
         default:
             throw new \yii\base\NotSupportedException("Unsupport imageX method!");
             break;
     }
     imagedestroy($this->image);
     //destory origin
     return ob_get_clean();
     //返回二进制数据流
 }
 public function save($handle, $uri = null)
 {
     if ($uri == null) {
         return imagegd($handle);
     }
     return imagegd($handle, $uri);
 }
Example #3
0
 function save($handle, $uri = null)
 {
     if ($uri == null) {
         return imagegd($handle);
     } else {
         return imagegd($handle, $uri);
     }
 }
Example #4
0
 /**
  * 按比例压缩图片
  * @param int $percent
  * @return string  二进制数据流
  */
 public function compress($percent)
 {
     $image = imagecreatefromstring($this->_StreamData);
     $width = imagesx($image);
     //原图width
     $height = imagesy($image);
     //原图height
     $t_w = $percent * $width;
     //缩略图width
     $t_h = $percent * $height;
     //缩略图height
     $thumb_img = imagecreatetruecolor($t_w, $t_h);
     imagecopyresampled($thumb_img, $image, 0, 0, 0, 0, $t_w, $t_h, $width, $height);
     ob_start();
     switch ($this->_mimetype) {
         case "gd2":
             imagegd2($thumb_img, null, 100);
             break;
         case "gd":
             imagegd($thumb_img, null, 100);
             break;
         case "gif":
             imagegif($thumb_img, null, 100);
             break;
         case "jpeg":
             imagejpeg($thumb_img, null, 100);
             break;
         case "jpg":
             imagejpeg($thumb_img, null, 100);
             break;
         case "png":
             imagepng($thumb_img, null, 100);
             break;
         default:
             throw new \yii\base\NotSupportedException("Unsupport imageX method!");
             break;
     }
     imagedestroy($image);
     //destory origin
     return ob_get_clean();
     //返回二进制数据流
 }
Example #5
0
<?php

$cwd = dirname(__FILE__);
echo "JPEG to GD1 conversion: ";
echo imagegd(imagecreatefromjpeg($cwd . "/conv_test.jpeg"), $cwd . "/test.gd1") ? 'ok' : 'failed';
echo "\n";
echo "JPEG to GD2 conversion: ";
echo imagegd2(imagecreatefromjpeg($cwd . "/conv_test.jpeg"), $cwd . "/test.gd2") ? 'ok' : 'failed';
echo "\n";
echo "GD1 to JPEG conversion: ";
echo imagejpeg(imagecreatefromgd($cwd . "/test.gd1"), $cwd . "/test_gd1.jpeg") ? 'ok' : 'failed';
echo "\n";
echo "GD2 to JPEG conversion: ";
echo imagejpeg(imagecreatefromgd2($cwd . "/test.gd2"), $cwd . "/test_gd2.jpeg") ? 'ok' : 'failed';
echo "\n";
@unlink($cwd . "/test.gd1");
@unlink($cwd . "/test.gd2");
@unlink($cwd . "/test_gd1.jpeg");
@unlink($cwd . "/test_gd2.jpeg");
Example #6
0
File: File.php Project: gtyd/jira
 /**
  * 将当前画布存放到文件中
  * @param resource $dst_im 目标文件的当前画布
  * @return resource 生成一个图片文件
  */
 public function _to($dst_im)
 {
     switch ($this->dst_img_ext) {
         case "gd2":
             imagegd2($dst_im, $this->dst_img);
             break;
         case "gd":
             imagegd($dst_im, $this->dst_img);
             break;
         case "gif":
             imagegif($dst_im, $this->dst_img);
             break;
         case "jpeg":
             imagejpeg($dst_im, $this->dst_img);
             break;
         case "jpg":
             imagejpeg($dst_im, $this->dst_img);
             break;
         case "png":
             imagepng($dst_im, $this->dst_img);
             break;
         default:
             break;
     }
     if (file_exists($this->dst_img)) {
         return TRUE;
     }
     return FALSE;
 }
Example #7
0
<?php

$cwd = dirname(__FILE__);
echo "XPM to GD1 conversion: ";
echo imagegd(imagecreatefromxpm($cwd . "/conv_test.xpm"), $cwd . "/test.gd1") ? 'ok' : 'failed';
echo "\n";
echo "XPM to GD2 conversion: ";
echo imagegd2(imagecreatefromxpm($cwd . "/conv_test.xpm"), $cwd . "/test.gd2") ? 'ok' : 'failed';
echo "\n";
@unlink($cwd . "/test.gd1");
@unlink($cwd . "/test.gd2");
<?php

$image = imagecreate(1, 1);
// 1px image
$tempdir = sys_get_temp_dir() . '/php-gdtest';
if (!file_exists($tempdir) && !is_dir($tempdir)) {
    mkdir($tempdir, 0777, true);
}
$userinput = "1";
// from post or get data
$temp = $tempdir . "/test" . $userinput . ".tmp";
echo "\nimagegd TEST\n";
imagegd($image, $temp);
var_dump(file_exists($tempdir . "/test1"));
var_dump(file_exists($tempdir . "/test1.tmp"));
foreach (glob($tempdir . "/test*") as $file) {
    unlink($file);
}
?>
$tempdir = sys_get_temp_dir(). '/php-gdtest';
foreach (glob($tempdir . "/test*") as $file ) { unlink($file); }
rmdir($tempdir);
 /**
  * Output an image
  *
  * @param   resource handle
  * @return  bool
  */
 public function output($handle)
 {
     return imagegd($handle);
 }
 function scale($x, $y, $filename = '', $distImageType = '')
 {
     if ($distImageType == 'gif') {
         $distImage = imagecreatetruecolor($x, $y);
         $this->copyResampled($distImage, $this->image, $x, $y);
         if (empty($filename)) {
             header("Content-Type: image/gif");
             $res = @imagejpeg($distImage, '', $this->quality);
         } else {
             imagegif($distImage, $filename, $this->quality);
         }
     } else {
         if ($distImageType == 'jpg' || $distImageType == 'jpeg') {
             $distImage = imagecreatetruecolor($x, $y);
             $this->copyResampled($distImage, $this->image, $x, $y);
             if (empty($filename)) {
                 header("Content-Type: image/jpeg");
                 imagejpeg($distImage, '', $this->quality);
             } else {
                 imagejpeg($distImage, $filename, $this->quality);
             }
         } else {
             if ($distImageType == 'png') {
                 $distImage = imagecreatetruecolor($x, $y);
                 $this->copyResampled($distImage, $this->image, $x, $y);
                 if (empty($filename)) {
                     header("Content-Type: image/png");
                     imagepng($distImage, '', $this->quality);
                 } else {
                     imagepng($distImage, $filename, $this->quality);
                 }
             } else {
                 if ($distImageType == 'gd') {
                     $distImage = imagecreatetruecolor($x, $y);
                     $this->copyResampled($distImage, $this->image, $x, $y);
                     if (empty($filename)) {
                         header("Content-Type: image/gd");
                         imagegd($distImage, '', $this->quality);
                     } else {
                         imagegd($distImage, $filename, $this->quality);
                     }
                 } else {
                     if ($distImageType == 'wbmp') {
                         $distImage = imagecreatetruecolor($x, $y);
                         $this->copyResampled($distImage, $this->image, $x, $y);
                         if (empty($filename)) {
                             header("Content-Type: image/wbmp");
                             imagewbmp($distImage, '', $this->quality);
                         } else {
                             imagewbmp($distImage, $filename, $this->quality);
                         }
                     } else {
                         die("Couldn't transform image!");
                     }
                 }
             }
         }
     }
 }
 /**
  * Output an image
  *
  * @param   resource handle
  * @return  bool
  */
 protected function output($handle)
 {
     return imagegd($handle);
 }
Example #12
0
 function output($a_mime = 'image/png')
 {
     $mime = trim(strtolower($a_mime));
     if ($this->m_handle) {
         ob_start();
         switch ($mime) {
             case 'jpg':
             case 'jpeg':
             case 'image/jpeg':
                 imagejpeg($this->m_handle);
                 break;
             case 'png':
             case 'image/png':
                 imagepng($this->m_handle);
                 break;
             case 'gif':
             case 'image/gif':
                 imagegif($this->m_handle);
                 break;
             case 'gd':
             case 'image/gd':
                 imagegd($this->m_handle);
                 break;
             case 'gd2':
             case 'image/gd2':
                 imagegd2($this->m_handle);
                 break;
             case 'bmp':
             case 'wbmp':
             case 'image/bmp':
             case 'image/wbmp':
                 imagewbmp($this->m_handle);
                 break;
         }
         ZResponse::getInstance()->setContent(ob_get_contents());
         ob_end_clean();
     }
     ZResponse::getInstance()->setContentType($mime);
 }
Example #13
0
 /**
  * Prints the Image
  * 
  * @param string $name
  * @param string $directory
  * @param string $imageType
  */
 private function saveImage($name, $directory, $imageType = 'png', $foreground = null)
 {
     switch ($imageType) {
         case 'jpg':
         case 'jpeg':
             imagejpeg($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'gif':
             imagegif($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'gd':
             imagegd($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'gd2':
             imagegd2($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'webp':
             imagewebp($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'wbmp':
             imagewbmp($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType, $foreground);
             break;
         case 'xbm':
             imagexbm($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType, $foreground);
             break;
         case 'svg':
         default:
             imagepng($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
     }
     imagedestroy($this->imageProperties[0]);
 }
Example #14
0
<?php

//print_r($GLOBALS);
//die($GLOBALS['HTTP_RAW_POST_DATA']);
if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
    $sData = $GLOBALS['HTTP_RAW_POST_DATA'];
    //header('Content-Type: application/octet-stream');
    header('Content-Type: image/jpg');
    header('Content-Disposition: attachment; filename=image.jpg');
    /*
    header('Content-Length: ' . strlen($sData));
    header('Pragma: cache');
    header('Cache-Control: public, must-revalidate, max-age=0');
    header('Connection: close');
    header('Expires: ' . date('r', time()+60*60));
    header('Last-Modified: ' . date('r', time()));
    */
    echo $sData;
    $oImg = imagecreatefromstring($sData);
    imagegd($oImg, null, 100);
    imagedestroy($oImg);
}
Example #15
0
 protected function _types()
 {
     $type = strtolower($this->type);
     if (!empty($this->save)) {
         $save = suffix($this->save, '.' . $type);
         $this->result['path'] = $save;
     } else {
         $save = NULL;
     }
     if ($type === 'jpeg') {
         if ($this->quality === 0) {
             $this->quality = 80;
         }
         imagejpeg($this->canvas, $save, $this->quality);
     } elseif ($type === 'png') {
         if ($this->quality === 0) {
             $this->quality = 8;
         }
         imagepng($this->canvas, $save, $this->quality);
     } elseif ($type === 'gif') {
         imagegif($this->canvas, $save);
     } elseif ($type === 'gd') {
         imagegd($this->canvas, $save);
     } elseif ($type === 'gd2') {
         imagegd2($this->canvas, $save, $this->quality);
     } elseif ($type === 'wbmp') {
         imagewbmp($this->canvas, $save, $this->quality);
     } elseif ($type === 'xbm') {
         imagexbm($this->canvas, $save, $this->quality);
     } elseif ($type === 'xpm') {
         imagexpm($this->canvas, $save, $this->quality);
     } elseif ($type === 'webp') {
         imagewebp($this->canvas, $save, $this->quality);
     }
     return $this;
 }
Example #16
0
<?php

$cwd = dirname(__FILE__);
echo "GIF to GD1 conversion: ";
echo imagegd(imagecreatefromgif($cwd . "/conv_test.gif"), $cwd . "/test.gd1") ? 'ok' : 'failed';
echo "\n";
echo "GIF to GD2 conversion: ";
echo imagegd2(imagecreatefromgif($cwd . "/conv_test.gif"), $cwd . "/test.gd2") ? 'ok' : 'failed';
echo "\n";
@unlink($cwd . "/test.gd1");
@unlink($cwd . "/test.gd2");
Example #17
0
 /**
  * Save the image in given path.
  *
  * @access	public
  * @param	string	$sPath		path
  * @param	integer	$iQuality	only if jpg/jpeg
  * @return	\Image
  * @since	1.0.0
  * @version	1.1.7, 2014-07-15
  */
 public function save($sPath, $iQuality = 100)
 {
     $sPath = str_replace('/', DIRECTORY_SEPARATOR, $sPath);
     $aExplodedPath = explode('.', $sPath);
     $iType = static::extensionToImageType(end($aExplodedPath));
     if (\FileManager::prepareDir($sPath, TRUE) === FALSE) {
         throw new \Plethora\Exception\Fatal('Can\'t create particular path ("' . $sPath . '").');
     }
     switch ($iType) {
         case self::PNG:
             imagepng($this->rImage, $sPath);
             break;
         case self::JPEG:
             imagejpeg($this->rImage, $sPath, $iQuality);
             break;
         case self::GIF:
             imagegif($this->rImage, $sPath);
             break;
         case self::GD:
             imagegd($this->rImage, $sPath);
             break;
         case self::GD2:
             imagegd2($this->rImage, $sPath);
             break;
     }
     return $this;
 }
Example #18
0
 /**
  * Calculate the visual complexity of the image
  *
  * Provides a fast method for determining visual complexity of
  * an image by comparing a raw image size to jpeg image file size.
  * The JPEG compression algorithm is really good at compressing
  * repetitive areas (low detail) areas of an image and gives us
  * a good enough indicator for the complexity in an image.
  *
  * @author Jonathan Davis
  * @since 1.3.4
  *
  * @return float A complexity amount (jpeg size to raw gd size)
  **/
 public function complexity()
 {
     $image =& $this->src->image;
     if (false !== $this->complexity) {
         return $this->complexity;
     }
     ob_start();
     imagegd($image);
     $source = strlen(ob_get_clean());
     ob_start();
     imagejpeg($image);
     $jpeg = strlen(ob_get_clean());
     $this->complexity = 0.7 - $jpeg / $source;
     return $this->complexity;
 }
Example #19
0
 /**
  * create basemap, save as gd image and return the image resource
  * @access private
  */
 function &_createBasemap($file)
 {
     //figure out what we're mapping in internal coords
     $left = $this->map_x;
     $bottom = $this->map_y;
     $right = $left + floor($this->image_w / $this->pixels_per_km) - 1;
     $top = $bottom + floor($this->image_h / $this->pixels_per_km) - 1;
     //if the scale <0 we generate the image at 1pix/km and then rescale it
     if ($this->pixels_per_km < 1) {
         $imgw = $right - $left;
         $imgh = $top - $bottom;
         $pixels_per_km = 1;
     } else {
         $imgw = $this->image_w;
         $imgh = $this->image_h;
         $pixels_per_km = $this->pixels_per_km;
     }
     $img = imagecreatetruecolor($imgw, $imgh);
     //fill in with sea
     $blue = imagecolorallocate($img, $this->colour['sea'][0], $this->colour['sea'][1], $this->colour['sea'][2]);
     imagefill($img, 0, 0, $blue);
     $rmin = $this->colour['sea'][0];
     $rmax = $this->colour['land'][0];
     $gmin = $this->colour['sea'][1];
     $gmax = $this->colour['land'][1];
     $bmin = $this->colour['sea'][2];
     $bmax = $this->colour['land'][2];
     //set greens to use for percentages
     $land = array();
     for ($p = 0; $p <= 100; $p++) {
         $scale = $p / 100;
         $r = round($rmin + ($rmax - $rmin) * $scale);
         $g = round($gmin + ($gmax - $gmin) * $scale);
         $b = round($bmin + ($bmax - $bmin) * $scale);
         $land[$p] = imagecolorallocate($img, $r, $g, $b);
     }
     //paint the land
     $db =& $this->_getDB();
     $rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
     //now plot all squares in the desired area
     $sql = "select x,y,percent_land,reference_index from gridsquare where \n\t\t\tCONTAINS( GeomFromText({$rectangle}),\tpoint_xy)";
     $recordSet =& $db->Execute($sql);
     while (!$recordSet->EOF) {
         $gridx = $recordSet->fields[0];
         $gridy = $recordSet->fields[1];
         $imgx1 = ($gridx - $left) * $pixels_per_km;
         //$imgy1=(($gridy-$bottom)* $pixels_per_km);
         $imgy1 = $imgh - ($gridy - $bottom + 1) * $pixels_per_km;
         if ($pixels_per_km == 1) {
             imagesetpixel($img, $imgx1, $imgy1, $land[$recordSet->fields[2]]);
         } else {
             $imgx2 = $imgx1 + $pixels_per_km;
             $imgy2 = $imgy1 + $pixels_per_km;
             imagefilledrectangle($img, $imgx1, $imgy1, $imgx2, $imgy2, $land[$recordSet->fields[2]]);
         }
         $recordSet->MoveNext();
     }
     $recordSet->Close();
     //resample?
     if ($imgw != $this->image_w) {
         //resample image, save it and return
         $resized = imagecreatetruecolor($this->image_w, $this->image_h);
         imagecopyresampled($resized, $img, 0, 0, 0, 0, $this->image_w, $this->image_h, $imgw, $imgh);
         imagegd($resized, $file);
         imagedestroy($img);
         return $resized;
     } else {
         //image is correct size, save it and return
         imagegd($img, $file);
         return $img;
     }
 }
 /**
  * returns a GD image instance for a square thumbnail of the image
  */
 function getSquareThumb($size)
 {
     $ab = sprintf("%02d", floor($this->gridimage_id % 1000000 / 10000));
     $cd = sprintf("%02d", floor($this->gridimage_id % 10000 / 100));
     $abcdef = sprintf("%06d", $this->gridimage_id);
     $hash = $this->_getAntiLeechHash();
     $img = null;
     $base =& $_SERVER['DOCUMENT_ROOT'];
     if ($this->gridimage_id < 1000000) {
         $thumbpath = "/photos/{$ab}/{$cd}/{$abcdef}_{$hash}_{$size}x{$size}.gd";
     } else {
         $yz = sprintf("%02d", floor($this->gridimage_id / 1000000));
         $thumbpath = "/geophotos/{$yz}/{$ab}/{$cd}/{$abcdef}_{$hash}_{$size}x{$size}.gd";
     }
     if (!file_exists($base . $thumbpath)) {
         //get path to fullsize image
         $fullpath = $this->_getFullpath();
         if ($fullpath != '/photos/error.jpg' && file_exists($base . $fullpath)) {
             //generate resized image
             $fullimg = @imagecreatefromjpeg($base . $fullpath);
             if ($fullimg) {
                 $srcw = imagesx($fullimg);
                 $srch = imagesy($fullimg);
                 if ($srcw == 0 && $srch == 0) {
                     //couldn't read image!
                     $img = null;
                     imagedestroy($fullimg);
                 } else {
                     //crop percentage is how much of the
                     //image to keep in the thumbnail
                     $crop = 0.75;
                     //figure out size of image we'll keep
                     if ($srcw > $srch) {
                         //landscape
                         $s = $srch * $crop;
                     } else {
                         //portrait
                         $s = $srcw * $crop;
                     }
                     $srcx = round(($srcw - $s) / 2);
                     $srcy = round(($srch - $s) / 2);
                     $srcw = $s;
                     $srch = $s;
                     $img = imagecreatetruecolor($size, $size);
                     imagecopyresampled($img, $fullimg, 0, 0, $srcx, $srcy, $size, $size, $srcw, $srch);
                     require_once 'geograph/image.inc.php';
                     UnsharpMask($img, 200, 0.5, 3);
                     imagedestroy($fullimg);
                     //save the thumbnail
                     imagegd($img, $base . $thumbpath);
                 }
             } else {
                 //couldn't load full jpeg
                 $img = null;
             }
         } else {
             //no original image!
             $img = null;
         }
     } else {
         $img = imagecreatefromgd($base . $thumbpath);
     }
     return $img;
 }