PHP怎么获取屏幕的宽度与高度

PHP怎么获取屏幕的宽度与高度,第1张

PHP是无法获取屏幕的高度和宽度的,你可以用JS来获取

Javascript:

    网页可见区域宽: documentbodyclientWidth

网页可见区域高:

documentbodyclientHeight

网页可见区域宽: documentbodyoffsetWidth

(包括边线的宽)

网页可见区域高: documentbodyoffsetHeight (包括边线的高)

网页正文全文宽:

documentbodyscrollWidth

网页正文全文高: documentbodyscrollHeight

网页被卷去的高:

documentbodyscrollTop

网页被卷去的左: documentbodyscrollLeft

网页正文部分上:

windowscreenTop

网页正文部分左: windowscreenLeft

屏幕分辨率的高:

windowscreenheight

屏幕分辨率的宽: windowscreenwidth

屏幕可用工作区高度:

windowscreenavailHeight

屏幕可用工作区宽度: windowscreenavailWidth

JQuery:

$(document)ready(function(){

alert($(window)height()); //浏览器当前窗口可视区域高度

alert($(document)height()); //浏览器当前窗口文档的高度

alert($(documentbody)height());//浏览器当前窗口文档body的高度

alert($(documentbody)outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin

alert($(window)width()); //浏览器当前窗口可视区域宽度

alert($(document)width());//浏览器当前窗口文档对象宽度

alert($(documentbody)width());//浏览器当前窗口文档body的宽度

alert($(documentbody)outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin

})

直接使用THINKPHP自带的方法就能获取了,你可以参考以下代码!

$image = new \Think\Image(); 

$image->open('/1jpg');

$width = $image->width(); // 返回的宽度

$height = $image->height(); // 返回的高度

$type = $image->type(); // 返回的类型

$mime = $image->mime(); // 返回的mime类型

$size = $image->size(); // 返回的尺寸数组 0 宽度 1 高度

原生PHP是这样的:

//int filesize ( string $filename )

// 输出类似:somefiletxt: 1024 bytes

$filename = 'somefiletxt';

echo $filename  ': '  filesize($filename)  ' bytes';

用php给你运行了一个

$txt='[img=442,296]地址1[/img]

[img=300,188]地址2[/img]

[img=120,206]地址3[/img]';

$re='/\[img\=(\d+,\d+)\](\S+)\[\/img\]/';//这里修改下,加上一个防止以单行文本导致的定界符不准问题

$arr=[];

preg_match_all($re,$txt,$arr);

var_dump($arr);

运行结果如下

php testphp

array(3) {

  [0]=>

  array(3) {

    [0]=>

    string(32) "[img=442,296]地址1[/img]"

    [1]=>

    string(32) "[img=300,188]地址2[/img]"

    [2]=>

    string(32) "[img=120,206]地址3[/img]"

  }

  [1]=>

  array(3) {

    [0]=>

    string(7) "442,296"

    [1]=>

    string(7) "300,188"

    [2]=>

    string(7) "120,206"

  }

  [2]=>

  array(3) {

    [0]=>

    string(13) "地址1"

    [1]=>

    string(13) "地址2"

    [2]=>

    string(13) "地址3"

  }

}

//增加一个矩阵转换

$txt = '[img=442,296]地址1[/img][img=300,188]地址2[/img][img=120,206]地址3[/img][img=120,206]>

1、首先不知道你所谓的卡通是什么样子的?

2、经过PS后(你提到了卡通效果)应该在饱和度、某点的颜色值都发生了变化,当然色深度也有可能变了。

提供一个思路:将两张在内存中都转化为,相同色深的位图,然后灰度处理,再然后利用边缘检测法判断边缘(这里是有局限性的,需要背景比较明显,如果背景也是图像效果不好,此法的代码在网上应该可以找到)。然后记录边缘的矩阵值,把两个做比较,设置允许差错范围(比如100边缘数据里有90个以上的值一致就认为是同一张图)

当然,在处理速度上你自己再看看二次样条、傅利叶、插值等算法吧…

哥们,你这个项目不是个小项目呀!如果真是个本科生的毕设,那个学校的老师也太牛了!如果有这个学校,我希望到那里上研!强……

补充:轮廓提取算法

/

函数名称:

ContourDIB()

参数:

LPSTR lpDIBBits - 指向源DIB图像指针

LONG lWidth - 源图像宽度(象素数,必须是4的倍数)

LONG lHeight - 源图像高度(象素数)

返回值:

BOOL - 运算成功返回TRUE,否则返回FALSE。

说明:

该函数用于对图像进行轮廓提取运算。

要求目标图像为只有0和255两个灰度值的灰度图像。

/

BOOL WINAPI ContourDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)

{

// 指向源图像的指针

LPSTR lpSrc;

// 指向缓存图像的指针

LPSTR lpDst;

// 指向缓存DIB图像的指针

LPSTR lpNewDIBBits;

HLOCAL hNewDIBBits;

//循环变量

long i;

long j;

unsigned char n,e,s,w,ne,se,nw,sw;

//像素值

unsigned char pixel;

// 暂时分配内存,以保存新图像

hNewDIBBits = LocalAlloc(LHND, lWidth lHeight);

if (hNewDIBBits == NULL)

{

// 分配内存失败

return FALSE;

}

// 锁定内存

lpNewDIBBits = (char )LocalLock(hNewDIBBits);

// 初始化新分配的内存,设定初始值为255

lpDst = (char )lpNewDIBBits;

memset(lpDst, (BYTE)255, lWidth lHeight);

for(j = 1; j <lHeight-1; j++)

{

for(i = 1;i <lWidth-1; i++)

{

// 指向源图像倒数第j行,第i个象素的指针

lpSrc = (char )lpDIBBits + lWidth j + i;

// 指向目标图像倒数第j行,第i个象素的指针

lpDst = (char )lpNewDIBBits + lWidth j + i;

注意要转换为unsigned char型

pixel = (unsigned char)lpS

//取得当前指针处的像素值,rc;

//目标图像中含有0和255外的其它灰度值

// if(pixel != 255 && pixel != 0)

// return FALSE;

if(pixel == 0)

{

lpDst = (unsigned char)0;

nw = (unsigned char)(lpSrc + lWidth -1);

n = (unsigned char)(lpSrc + lWidth );

ne = (unsigned char)(lpSrc + lWidth +1);

w = (unsigned char)(lpSrc -1);

e = (unsigned char)(lpSrc +1);

sw = (unsigned char)(lpSrc - lWidth -1);

s = (unsigned char)(lpSrc - lWidth );

se = (unsigned char)(lpSrc - lWidth +1);

//如果相邻的八个点都是黑点

if(nw+n+ne+w+e+sw+s+se==0)

{

lpDst = (unsigned char)255;

}

}

}

}

// 复制腐蚀后的图像

memcpy(lpDIBBits, lpNewDIBBits, lWidth lHeight);

// 释放内存

LocalUnlock(hNewDIBBits);

LocalFree(hNewDIBBits);

// 返回

return TRUE;

}

/

函数名称:

TraceDIB()

参数:

LPSTR lpDIBBits - 指向源DIB图像指针

LONG lWidth - 源图像宽度(象素数,必须是4的倍数)

LONG lHeight - 源图像高度(象素数)

返回值:

BOOL - 运算成功返回TRUE,否则返回FALSE。

说明:

该函数用于对图像进行轮廓跟踪运算。

要求目标图像为只有0和255两个灰度值的灰度图像。

/

BOOL WINAPI TraceDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)

{

// 指向源图像的指针

LPSTR lpSrc;

// 指向缓存图像的指针

LPSTR lpDst;

// 指向缓存DIB图像的指针

LPSTR lpNewDIBBits;

HLOCAL hNewDIBBits;

// 图像每行的字节数

LONG lLineBytes;

//循环变量

long i;

long j;

//像素值

unsigned char pixel;

//是否找到起始点及回到起始点

bool bFindStartPoint;

//是否扫描到一个边界点

bool bFindPoint;

//起始边界点与当前边界点

Point StartPoint,CurrentPoint;

//八个方向和起始扫描方向

int Direction[8][2]={{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0}};

int BeginDirect;

// 计算图像每行的字节数

lLineBytes = WIDTHBYTES(lWidth 8);

// 暂时分配内存,以保存新图像

hNewDIBBits = LocalAlloc(LHND, lLineBytes lHeight);

if (hNewDIBBits == NULL)

{

// 分配内存失败

return FALSE;

}

// 锁定内存

lpNewDIBBits = (char )LocalLock(hNewDIBBits);

// 初始化新分配的内存,设定初始值为255

lpDst = (char )lpNewDIBBits;

memset(lpDst, (BYTE)255, lLineBytes lHeight);

//先找到最左上方的边界点

bFindStartPoint = false;

for (j = 0;j < lHeight && !bFindStartPoint;j++)

{

for(i = 0;i < lWidth && !bFindStartPoint;i++)

{

// 指向源图像倒数第j行,第i个象素的指针

lpSrc = (char )lpDIBBits + lLineBytes j + i;

//取得当前指针处的像素值,注意要转换为unsigned char型

pixel = (unsigned char)lpSrc;

if(pixel == 0)

{

bFindStartPoint = true;

StartPointHeight = j;

StartPointWidth = i;

// 指向目标图像倒数第j行,第i个象素的指针

lpDst = (char )lpNewDIBBits + lLineBytes j + i;

lpDst = (unsigned char)0;

}

}

}

//由于起始点是在左下方,故起始扫描沿左上方向

BeginDirect = 0;

//跟踪边界

bFindStartPoint = false;

//从初始点开始扫描

CurrentPointHeight = StartPointHeight;

CurrentPointWidth = StartPointWidth;

while(!bFindStartPoint)

{

bFindPoint = false;

while(!bFindPoint)

{

//沿扫描方向查看一个像素

lpSrc = (char )lpDIBBits + lLineBytes ( CurrentPointHeight + Direction[BeginDirect][1])

+ (CurrentPointWidth + Direction[BeginDirect][0]);

pixel = (unsigned char)lpSrc;

if(pixel == 0)

{

bFindPoint = true;

CurrentPointHeight = CurrentPointHeight + Direction[BeginDirect][1];

CurrentPointWidth = CurrentPointWidth + Direction[BeginDirect][0];

if(CurrentPointHeight == StartPointHeight && CurrentPointWidth == StartPointWidth)

{

bFindStartPoint = true;

}

lpDst = (char )lpNewDIBBits + lLineBytes CurrentPointHeight + CurrentPointWidth;

lpDst = (unsigned char)0;

//扫描的方向逆时针旋转两格

BeginDirect--;

if(BeginDirect == -1)

BeginDirect = 7;

BeginDirect--;

if(BeginDirect == -1)

BeginDirect = 7;

}

else

{

//扫描方向顺时针旋转一格

BeginDirect++;

if(BeginDirect == 8)

BeginDirect = 0;

}

}

}

// 复制腐蚀后的图像

memcpy(lpDIBBits, lpNewDIBBits, lWidth lHeight);

// 释放内存

LocalUnlock(hNewDIBBits);

LocalFree(hNewDIBBits);

// 返回

return TRUE;

}

以上就是关于PHP怎么获取屏幕的宽度与高度全部的内容,包括:PHP怎么获取屏幕的宽度与高度、thinkphp 怎么用程序自动判断压缩图片的大小、请问怎样用php 正则表达式取设置宽和高的[img][/img]标签里面的图片地址等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9296789.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-26
下一篇2023-04-26

发表评论

登录后才能评论

评论列表(0条)

    保存