使用PHP获得屏幕分辨率,以便在图片库中使用
浏览量:364
what:
上一篇文章《php以图片中心为基准任意调整图片尺寸并输出显示》说了用php处理图片输出,这样可以自定义图片尺寸,保存一个,可以输出任意尺寸的图片。
这不,想输出全屏大小的图片,就要知道屏幕的分辨率,单独使用php没法获得客户端的分辨率,所以用php+js结合的方法实现。
how:
实现:
session_start();
if(isset($_SESSION['screen_width']) AND isset($_SESSION['screen_height'])){
//echo $_SESSION['screen_width'];
//echo '<br>';
//echo $_SESSION['screen_height'];
echo '<script type="text/javascript">window.location="a.php?d='.$_GET['d'].'";</script>';
}elseif(isset($_GET['width']) AND isset($_GET['height'])){
$_SESSION['screen_width']=$_GET['width'];
$_SESSION['screen_height']=$_GET['height'];
echo '<script type="text/javascript">window.location="a.php?d='.$_GET['d'].'";</script>';
}else{
echo '<script type="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?width="+screen.width+"&height="+screen.height+"&d='.$_GET['d'].'";</script>';
}


感谢支持与鼓励~