使用cookie和JavaScript的响应式图像 [英] Responsive images using the cookie and JavaScript

查看:58
本文介绍了使用cookie和JavaScript的响应式图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#创建响应式图像

我在php中有代码并想在c中使用相同的代码#

谢谢

I wanna create responsive image using C#
I have code in php and wanna same code in c#
thank you

<script >

 document.cookie = "screen_dimensions=" + screen.width + "x" +

screen.height;

</script>










<?php

 $screen_w = 0;

 $screen_h = 0;

 $img = $_SERVER['QUERY_STRING'];

 if (file_exists($img)) {

 // Get screen dimensions from the cookie

 if (isset($_COOKIE['screen_dimensions'])) {

 $screen = explode('x', $_COOKIE['screen_dimensions']);

 if (count($screen)==2) {

 $screen_w = intval($screen[0]);

 $screen_h = intval($screen[1]);

 }

 }

if ($screen_width> 0) {

 $theExt = pathinfo($img, PATHINFO_EXTENSION);

 // for Low resolution screen

 if ($screen_width>= 1024) {

 $output = substr_replace($img, '-med', -strlen($theExt)-1,

 }

 // for Medium resolution screen

 else if ($screen_width<= 800) {

 $output = substr_replace($img, '-low', -strlen($theExt)-1, 0);

 }

 // check if file exists

 if (isset($output) &&file_exists($output)) {

 $img = $output;

 }

 }

 // return the image file;

 readfile($img);

 }

?>

推荐答案

screen_w = 0 ;

screen_w = 0;


screen_h = 0 ;

screen_h = 0;


img =
img =


这篇关于使用cookie和JavaScript的响应式图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆