动态背景图片 PHP GD
问题 基本上,在我看来,不可能以正确的方式使用带有背景图像的全尺寸照片。 不同的分辨率,宽屏等等。我正在寻找一个针对这个问题的 JS/PHP GD 解决方案。
技术 据我所知,情况如下。 JavaScript 查找可用的屏幕尺寸(浏览器窗口)或屏幕分辨率。 将其解析为 PHP GD。 在 FTP 上,您将获得高分辨率图像(例如 1600x1200)。 PHP GD 根据 JS 解析的信息对此进行缩放。 这也必须适用于Resize。
由于我“只是”一个简单的设计师,我对 JS/PHP 的缺乏让我在这个问题上丧命。
如果有人可以帮助我找到适当的解决方案,我很乐意在完成后在我的新网站上将他们添加为朋友链接。 预先感谢荷兰的厚爱。
菲尔
Problem
Basicly, it's impossible to use a full-size photograph with the background-image in a proper way imo.
Different resolutions, wide-screen etc etc. What im looking for is a JS/PHP GD solution for this problem.
Technique
From what i hear, it would be as follows. Javascript looks up available screensize (browser window) or screenresolution. Parses this to PHP GD. On the FTP you'll have a high-res image (1600x1200 for example). The PHP GD scales this according to the information parsed by JS.
This will also have to work onResize.
Since im 'just' a simple designer, my lack of JS/PHP is killing me over this issue.
If anyone can help me out with a proper solution, i would love to friend-link them on my new site once it's finished. Thanks in advance and much love from Holland.
Phil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是你的观点,但网络上的其他人似乎不同意你的观点。 他们让它发挥作用。 但这可能不是这里的主要问题。
为每个用户调整背景大小,如果你不缓存的话,每个请求都会在一纳秒内摧毁你的服务器。 GD 调整大小的成本很高,如果这是在共享主机上,您最终会被踢掉您的网站。 如果同一服务器上还有其他网站,它们的速度就会慢得像爬行一样。
即使你可以向服务器中铲入足够的煤炭,它也会带来相当危险的用户体验。 浏览器不仅能够下载文件,还必须等待 PHP 生成图像,然后才能下载。
如果我在大屏幕上加载该网站会怎样? 我这里可能有大约 3840*1200 的分辨率。 即使你不扩展它,我也必须下载完整版本。 大屏幕尺寸并不意味着我的计算机有多余的光纤。
但是,尽管如此,这当然是可能的。 我建议您从 jQuery 开始。 它使得挂钩 window -load 和 -resize 事件并动态更改 CSS 变得非常简单。 可以通过一些简单的谷歌来完成具体的细节:“php resize image”,“jquery onresize”和“jquery change background”。
I know that's your opinion but the rest of the web appears to disagree with you. They make it work. But that's probably not the major issue here.
Resizing a background for every user, hell, every request if you don't cache, is going to nuke your server in a nanosecond. GD resizes are expensive and if this is on shared hosting, you'll end up having your site kicked off it. If there are other sites on the same server, they'll slow to a crawl.
Even if you can shovel enough coal into the server, it's going to make for a pretty dodgy user experience. Rather than just being able to download the file, the browser is going to have to wait while the PHP generates the image and only then can it download.
And what if I loaded this site on a large screen? I've got a possible ~3840*1200 resolution here. Even if you don't scale it up, I'll have to download the full version. A large screen size doesn't mean I have redundant optical fibres to my computer.
But, all that said, it's certainly possible. I'd recommend you start with jQuery. It makes hooking onto window -load and -resize events and changing the CSS dynamically pretty simple. The gritty details can be accomplished with a few simple googles: "php resize image", "jquery onresize" and "jquery change background".
您还可以制作多个 CSS 样式表来匹配某些分辨率。 这个未经测试的例子可能会给你一些帮助。
You also can make several css style sheet to match some resolutions. this UNTESTED example may give you some help.
你完全可以用 CSS 来做到这一点。
看看包含和覆盖: https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
奖励:http://blog.geniccoder.com/2015/12/09/rotate-and -cross-fade-background-images-with-jquery-css-background-opacity-trick/
you can do this entirely with CSS..
Look at contain and cover: https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
Bonus: http://blog.geneticcoder.com/2015/12/09/rotate-and-cross-fade-background-images-with-jquery-css-background-opacity-trick/