本文整理汇总了PHP中imagewbmp函数的典型用法代码示例。如果您正苦于以下问题:PHP imagewbmp函数的具体用法?PHP imagewbmp怎么用?PHP imagewbmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagewbmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImage
/**
* Get the image in a specific format
* @param string|null $format optional format to get the image in, if null the source image format is used
* @return string binary string of the converted image
*/
public function getImage(string $format = null) : string
{
if (!$format) {
$format = explode('/', $this->info['mime'], 2)[1];
}
switch (strtolower($format)) {
case 'jpg':
case 'jpeg':
ob_start();
imagejpeg($this->data);
return ob_get_clean();
case 'bitmap':
case 'bmp':
ob_start();
imagewbmp($this->data);
return ob_get_clean();
case 'png':
ob_start();
imagepng($this->data);
return ob_get_clean();
case 'gif':
ob_start();
imagegif($this->data);
return ob_get_clean();
case 'webp':
ob_start();
imagewebp($this->data, null);
return ob_get_clean();
default:
throw new ImageException('Unsupported format');
}
}
示例2: display
function display()
{
ob_end_flush();
ob_start();
switch (strtolower($this->format)) {
case 'jpeg':
case 'jpg':
imagejpeg($this->data);
break;
case 'gif':
imagegif($this->data);
break;
case 'png':
imagepng($this->data);
break;
case 'wbmp':
imagewbmp($this->data);
break;
default:
ob_end_clean();
return NULL;
}
$image = ob_get_contents();
ob_end_clean();
return $image;
}
示例3: genFile
public function genFile($fileName, $quality = 100)
{
$image = parent::returnThumbnail();
$result = false;
if (!empty($image)) {
switch ($this->image_type) {
case 1:
$result = imagegif($image, $fileName);
break;
case 2:
$quality = (int) $quality;
if ($quality < 0 || $quality > 100) {
$quality = 75;
}
// end if
$result = imagejpeg($image, $fileName, $quality);
break;
case 3:
$result = imagepng($image, $fileName);
break;
case 15:
$result = imagewbmp($image, $fileName);
break;
}
// end switch
}
return $result;
}
示例4: index
public function index($image_id)
{
$result = mysqli_fetch_array($this->db->db_query("SELECT `Image` FROM `Restaurant_Images` where `idRestaurant_Images` = '{$image_id}'"));
$uri = 'data://application/octet-stream;base64,' . base64_encode($result['Image']);
$image_type = getimagesize($uri);
if ($result !== NULL) {
header('Content-Type: ', $image_type['mime']);
$image = imagecreatefromstring($result['Image']);
switch ($image_type['mime']) {
case 'image/jpeg':
imagejpeg($image);
break;
case 'image/bmp':
imagewbmp($image);
break;
case 'image/gif':
imagegif($image);
break;
case 'image/png':
imagepng($image);
break;
default:
echo "Unsupported picture type: " . $image_type;
return;
}
imagedestroy($image);
} else {
header('Content-Type: image/png');
$fp = fopen(APP_ROOT . '/img/restaurant.png', 'r');
fpassthru($fp);
}
}
示例5: createImageFile
/**
* @brief 生成图片文件
* @param resource $imageRes 图片资源名称
* @param string $thumbFileName 缩略图名称
* @param bool $imageResult 生成缩略图状态 true:成功; false:失败;
*/
public static function createImageFile($imageRes, $thumbFileName)
{
//如果目录不可写直接返回,防止错误抛出
if (!is_writeable(dirname($thumbFileName))) {
return false;
}
$imageResult = false;
//获取文件扩展名
$fileExt = IFile::getFileSuffix($thumbFileName);
switch ($fileExt) {
case 'jpg':
case 'jpeg':
$imageResult = imagejpeg($imageRes, $thumbFileName, 100);
break;
case 'gif':
$imageResult = imagegif($imageRes, $thumbFileName);
break;
case 'png':
$imageResult = imagepng($imageRes, $thumbFileName);
break;
case 'bmp':
$imageResult = imagewbmp($imageRes, $thumbFileName);
break;
}
return $imageResult;
}
示例6: resize
function resize($filename, $size, $quality)
{
$dir = UPLOADDIR;
// Адрес директории для сохранения картинки
$ext = strtolower(strrchr(basename($filename), "."));
// Получаем формат уменьшаемого изображения
$extentions = array('.jpg', '.gif', '.png', '.bmp');
// Определяем формат уменьшаемой картинки
if (in_array($ext, $extentions)) {
echo '01';
$percent = $size;
// Ширина изображения миниатюры
list($width, $height) = getimagesize(UPLOADDIR . $filename);
// Возвращает ширину и высоту картинки
$newheight = $height * $percent;
$newwidth = $newheight / $width;
$thumb = imagecreatetruecolor($percent, $newwidth);
switch ($ext) {
case '.jpg':
$source = @imagecreatefromjpeg(UPLOADDIR . $filename);
break;
case '.gif':
$source = @imagecreatefromgif(UPLOADDIR . $filename);
break;
case '.png':
$source = @imagecreatefrompng(UPLOADDIR . $filename);
break;
case '.bmp':
$source = @imagecreatefromwbmp(UPLOADDIR . $filename);
break;
}
// php уменьшение изображения
imagecopyresized($thumb, $source, 0, 0, 0, 0, $percent, $newwidth, $width, $height);
// Создаем изображение
switch ($ext) {
case '.jpg':
imagejpeg($thumb, UPLOADDIR . "min_" . $filename, $quality);
// Для JPEG картинок
break;
case '.gif':
imagegif($thumb, UPLOADDIR . $filename);
// Для GIF картинки
break;
case '.png':
imagepng($thumb, UPLOADDIR . $filename, $quality);
// Для PNG картинок
break;
case '.bmp':
imagewbmp($thumb, UPLOADDIR . $filename);
// Для BMP картинки
break;
}
} else {
return 'typeError';
}
@imagedestroy($thumb);
@imagedestroy($source);
return $filename;
}
示例7: make_thumb
/**
* Make a thumbnail of a newly uploaded file if it is an image
*
* @param $src the source of the file
* @param $dest where to save the thumbnail
* @param $fileExt the file extension (to check if the file is an image)
* @param $desired_width the desired width of the thumbnail, height and width are kept in ratio
*/
function make_thumb($src, $dest, $fileExt, $desired_width)
{
$exif = exif_read_data($src, 'IFD0');
// Read the source image
if ($fileExt == 'gif') {
$source_image = imagecreatefromgif($src);
} elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
$source_image = imagecreatefromjpeg($src);
} elseif ($fileExt == 'png') {
$source_image = imagecreatefrompng($src);
} elseif ($fileExt == 'wbmp') {
$source_image = imagecreatefromwbmp($src);
} else {
// Return if not an image
return;
}
// Fix Orientation of original image - this has to be done because of stupid apple products who can't save their
// orientation like everybody else, ugh!
switch ($exif['Orientation']) {
case 3:
$source_image = imagerotate($source_image, 180, 0);
break;
case 6:
$source_image = imagerotate($source_image, -90, 0);
break;
case 8:
$source_image = imagerotate($source_image, 90, 0);
break;
}
// Save turned source image again (overwrites false orientation)
if ($fileExt == 'gif') {
imagegif($source_image, $src);
} elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
imagejpeg($source_image, $src);
} elseif ($fileExt == 'png') {
imagepng($source_image, $src);
} elseif ($fileExt == 'bmp') {
imagewbmp($source_image, $src);
}
$width = imagesx($source_image);
$height = imagesy($source_image);
// Find the "desired height" of this thumbnail, relative to the desired width
$desired_height = floor($height * ($desired_width / $width));
// Create a new, "virtual" image
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
// Copy source image at a resized size
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
// Create the physical thumbnail image to its destination
if ($fileExt == 'gif') {
imagegif($virtual_image, $dest);
} elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
imagejpeg($virtual_image, $dest);
} elseif ($fileExt == 'png') {
imagepng($virtual_image, $dest);
} elseif ($fileExt == 'bmp') {
imagewbmp($virtual_image, $dest);
}
}
示例8: create
public function create()
{
//набор символов
$letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'q', 'j', 'k', 'm', 'n', 'p', 'z', 'x', 'y', 's', 'u', 't', '2', '4', '5', '6', '7', '8', '9', '%', '+', '@', '#', '=', '?');
//цвета
$colors = array('90', '110', '130', '150', '170', '190', '210');
$src = imagecreatetruecolor($this->width, $this->height);
//создаем изображение
$fon = imagecolorallocate($src, 255, 255, 255);
//создаем фон
imagefill($src, 0, 0, $fon);
//заливаем изображение фоном
for ($i = 0; $i < $this->fon_let_amount; $i++) {
//случайный цвет
$color = imagecolorallocatealpha($src, rand(0, 255), rand(0, 255), rand(0, 255), 100);
//случайный символ
$letter = $letters[rand(0, sizeof($letters) - 1)];
//случайный размер
$size = rand($this->font_size - 2, $this->font_size + 2);
imagettftext($src, $size, rand(0, 45), rand($this->width * 0.1, $this->width - $this->width * 0.1), rand($this->height * 0.2, $this->height), $color, $this->font, $letter);
}
$code = array();
for ($i = 0; $i < $this->let_amount; $i++) {
$color = imagecolorallocatealpha($src, $colors[rand(0, sizeof($colors) - 1)], $colors[rand(0, sizeof($colors) - 1)], $colors[rand(0, sizeof($colors) - 1)], rand(20, 40));
$letter = $letters[rand(0, sizeof($letters) - 1)];
$size = rand($this->font_size * 2 - 2, $this->font_size * 2 + 2);
$x = ($i + 1) * $this->font_size + rand(1, 5);
//даем каждому символу случайное смещение
$y = $this->height * 2 / 3 + rand(0, 5);
$code[] = $letter;
//запоминаем код
imagettftext($src, $size, rand(0, 15), $x, $y, $color, $this->font, $letter);
}
$code = implode('', $code);
//переводим код в строку
// Обработка вывода
if (imagetypes() & IMG_JPG) {
// для JPEG
header('Content-Type: image/jpeg');
imagejpeg($src, NULL, 100);
} elseif (imagetypes() & IMG_PNG) {
// для PNG
header('Content-Type: image/png');
imagepng($src);
} elseif (imagetypes() & IMG_GIF) {
// для GIF
header('Content-Type: image/gif');
imagegif($src);
} elseif (imagetypes() & IMG_PNG) {
// для WBMP
header('Content-Type: image/vnd.wap.wbmp');
imagewbmp($src);
} else {
imagedestroy($src);
return;
}
Session::set_server_data(array('captcha' => $code));
}
示例9: build
public function build($text = '', $showText = true, $fileName = null)
{
if (trim($text) <= ' ') {
throw new exception('barCode::build - must be passed text to operate');
}
if (!($fileType = $this->outMode[$this->mode])) {
throw new exception("barCode::build - unrecognized output format ({$this->mode})");
}
if (!function_exists("image{$this->mode}")) {
throw new exception("barCode::build - unsupported output format ({$this->mode} - check phpinfo)");
}
$text = strtoupper($text);
$dispText = "* {$text} *";
$text = "*{$text}*";
// adds start and stop chars
$textLen = strlen($text);
$barcodeWidth = $textLen * (7 * $this->bcThinWidth + 3 * $this->bcThickWidth) - $this->bcThinWidth;
$im = imagecreate($barcodeWidth, $this->bcHeight);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $white);
$xpos = 0;
for ($idx = 0; $idx < $textLen; $idx++) {
if (!($char = $text[$idx])) {
$char = '-';
}
for ($ptr = 0; $ptr <= 8; $ptr++) {
$elementWidth = $this->codeMap[$char][$ptr] ? $this->bcThickWidth : $this->bcThinWidth;
if (($ptr + 1) % 2) {
imagefilledrectangle($im, $xpos, 0, $xpos + $elementWidth - 1, $this->bcHeight, $black);
}
$xpos += $elementWidth;
}
$xpos += $this->bcThinWidth;
}
if ($showText) {
$pxWid = imagefontwidth($this->fontSize) * strlen($dispText) + 10;
$pxHt = imagefontheight($this->fontSize) + 2;
$bigCenter = $barcodeWidth / 2;
$textCenter = $pxWid / 2;
imagefilledrectangle($im, $bigCenter - $textCenter, $this->bcHeight - $pxHt, $bigCenter + $textCenter, $this->bcHeight, $white);
imagestring($im, $this->fontSize, $bigCenter - $textCenter + 5, $this->bcHeight - $pxHt + 1, $dispText, $black);
}
if (!$fileName) {
header("Content-type: image/{$fileType}");
}
switch ($this->mode) {
case 'gif':
imagegif($im, $fileName);
case 'png':
imagepng($im, $fileName);
case 'jpeg':
imagejpeg($im, $fileName);
case 'wbmp':
imagewbmp($im, $fileName);
}
imagedestroy($im);
}
示例10: generate
/**
* {@inheritdoc}
*/
public function generate($output, $outputPath = null)
{
// WBMP foreground seem doesn't work...
if (!is_null($this->foreground)) {
imagewbmp($output, $outputPath, $this->foreground->getColor());
} else {
imagewbmp($output, $outputPath);
}
}
示例11: cropAction
public function cropAction(Request $request)
{
$imageId = $request->request->get('imageId');
/* @var $galleryImage GalleryImage */
$galleryImage = $this->getDoctrine()->getRepository('KarolineKroissGalleryBundle:GalleryImage')->findOneBy(['id' => $imageId]);
$targetWidth = 65;
$targetHeight = 65;
$quality = 100;
$src = $galleryImage->getAbsolutePath();
$src = $galleryImage->getUploadRootDir() . '/../../' . $galleryImage->getPreviewPath();
$dst = $galleryImage->getUploadRootDir() . '/../../' . $galleryImage->getThumbnailPath();
$type = strtolower(substr(strrchr($src, '.'), 1));
if ($type == 'jpeg') {
$type = 'jpg';
}
switch ($type) {
case 'bmp':
$imageResource = imagecreatefromwbmp($src);
break;
case 'gif':
$imageResource = imagecreatefromgif($src);
break;
case 'jpg':
$imageResource = imagecreatefromjpeg($src);
break;
case 'png':
$imageResource = imagecreatefrompng($src);
break;
default:
return 'Unsupported picture type!';
}
$destinationResource = imagecreatetruecolor($targetWidth, $targetHeight);
imagecopyresampled($destinationResource, $imageResource, 0, 0, $request->request->get('x'), $request->request->get('y'), $targetWidth, $targetHeight, $request->request->get('w'), $request->request->get('h'));
// preserve transparency
if ($type == 'gif' or $type == 'png') {
imagecolortransparent($destinationResource, imagecolorallocatealpha($destinationResource, 0, 0, 0, 127));
imagealphablending($destinationResource, false);
imagesavealpha($destinationResource, true);
}
switch ($type) {
case 'bmp':
imagewbmp($destinationResource, $dst);
break;
case 'gif':
imagegif($destinationResource, $dst);
break;
case 'jpg':
imagejpeg($destinationResource, $dst);
break;
case 'png':
imagepng($destinationResource, $dst);
break;
}
$request->headers->get('referer');
return new RedirectResponse($request->headers->get('referer'));
}
示例12: wbmp_to_zpl
/**
* Converts image file contents to ZPL "download graphic" command
*
* @param string $in image binary string
*
* @param string $name arbitrary filename
*
* @return string ZPL "download graphic" command
*/
function wbmp_to_zpl($in, $name = '')
{
if (empty($in)) {
return '';
}
// Load image
$im = imagecreatefromstring($in);
if ($im === false) {
return false;
}
// Black and white only
imagefilter($im, IMG_FILTER_GRAYSCALE);
//first, convert to grayscale
imagefilter($im, IMG_FILTER_CONTRAST, -255);
//then, apply a full contrast
// Convert to WBMP
ob_start();
imagewbmp($im);
$wbmp = ob_get_contents();
ob_end_clean();
$type = uintvar_shift($wbmp);
$fixed = uintvar_shift($wbmp);
$w = uintvar_shift($wbmp);
$h = uintvar_shift($wbmp);
$bitmap = ~$wbmp;
// Black is white, white is black
$total_bytes = strlen($bitmap);
$bytes_per_line = ceil($w / 8);
if ($w % 8 > 0) {
// End of line is padded with black; make that white
// Get last byte of each line
$period = ceil($w / 8);
for ($i = $bytes_per_line; $i <= $total_bytes; $i += $bytes_per_line) {
$byte = ord($bitmap[$i - 1]);
for ($j = 1; $j <= $w % 8; $j++) {
// Flip j-th bit
$byte = $byte & ~(1 << $j - 1);
}
$bitmap[$i - 1] = chr($byte);
}
}
$uncompressed = strtoupper(bin2hex($bitmap));
$compressed = preg_replace_callback('/(.)\\1{2,399}/', "zpl_rle_compress_helper", $uncompressed);
$name = preg_replace('/[^A-z0-9]/', '', $name);
if (strlen($name) > 8) {
$name = substr($name, 0, 8);
}
$name = strtoupper($name);
if (empty($name)) {
$name = rand(10000000, 99999999);
}
$r = "~DG" . $name . ".GRF," . $total_bytes . "," . $bytes_per_line . "," . $compressed;
return $r;
}
示例13: resizeImage
function resizeImage($image, $width, $height, $scale)
{
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
$ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
$source = "";
if ($ext == 'jpeg') {
$ext = 'jpg';
}
switch ($ext) {
case 'bmp':
$source = imagecreatefromwbmp($image);
break;
case 'gif':
$source = imagecreatefromgif($image);
break;
case 'jpg':
$source = imagecreatefromjpeg($image);
break;
case 'png':
$source = imagecreatefrompng($image);
break;
}
// preserve transparency
if ($ext == "gif" or $ext == "png") {
imagecolortransparent($source, imagecolorallocatealpha($source, 0, 0, 0, 127));
imagealphablending($newImage, false);
imagesavealpha($newImage, true);
}
imagecopyresampled($newImage, $source, 0, 0, 0, 0, $newImageWidth, $newImageHeight, $width, $height);
imageinterlace($newImage, true);
switch ($ext) {
case 'bmp':
imagewbmp($newImage, $image);
break;
case 'gif':
imagegif($newImage, $image);
break;
case 'jpg':
imagejpeg($newImage, $image, 100);
break;
case 'png':
imagepng($newImage, $image, 0);
break;
}
chmod($image, 0777);
return $image;
}
示例14: save
/**
* 将图片资源保存到文件
*
* @param string $output 输出文件路径
* @param string $outputType 输出类型, 默认为原图片类型
* @return bool
* @throws Exception
*/
public function save($output, $outputType = '')
{
$outputType or $outputType = $this->mime;
switch ($outputType) {
case 'image/gif':
return imagegif($this->resource, $output);
case 'image/jpeg':
return imagejpeg($this->resource, $output);
case 'image/png':
return imagepng($this->resource, $output);
case 'image/bmp':
return imagewbmp($this->resource, $output);
default:
throw new Exception("{$this->mime} type does not be image helper support");
}
}
示例15: ShowKey
function ShowKey()
{
$key = strtolower(domake_password(4));
$set = esetcookie("checkkey", $key);
//是否支持gd库
if (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
$img = imagecreate(69, 20);
$black = imagecolorallocate($img, 255, 255, 255);
$gray = imagecolorallocate($img, 102, 102, 102);
imagefill($img, 0, 0, $gray);
imagestring($img, 3, 14, 3, $key, $black);
imagejpeg($img);
imagedestroy($img);
} elseif (function_exists("imagegif")) {
header("Content-type: image/gif");
$img = imagecreate(69, 20);
$black = imagecolorallocate($img, 255, 255, 255);
$gray = imagecolorallocate($img, 102, 102, 102);
imagefill($img, 0, 0, $gray);
imagestring($img, 3, 14, 3, $key, $black);
imagegif($img);
imagedestroy($img);
} elseif (function_exists("imagepng")) {
header("Content-type: image/png");
$img = imagecreate(69, 20);
$black = imagecolorallocate($img, 255, 255, 255);
$gray = imagecolorallocate($img, 102, 102, 102);
imagefill($img, 0, 0, $gray);
imagestring($img, 3, 14, 3, $key, $black);
imagepng($img);
imagedestroy($img);
} elseif (function_exists("imagewbmp")) {
header("Content-type: image/vnd.wap.wbmp");
$img = imagecreate(69, 20);
$black = imagecolorallocate($img, 255, 255, 255);
$gray = imagecolorallocate($img, 102, 102, 102);
imagefill($img, 0, 0, $gray);
imagestring($img, 3, 14, 3, $key, $black);
imagewbmp($img);
imagedestroy($img);
} else {
$set = esetcookie("checkkey", "ebak");
@(include "class/functions.php");
echo ReadFiletext("images/ebak.jpg");
}
}