我试图做到这一点,每次有人在页面上捐赠一定金额时,图像的另一个等量部分就会被显示出来。 我已经掌握了大部分其他逻辑(PayPal 提供了很好的独特的“您已捐赠”标识符等),但是,我在一点一点地显示图像方面遇到了麻烦。
我尝试将图像分成小块(在图像完全显示之前,人们需要至少 250 份捐赠),但是,由于多种格式的图像,这不起作用。 有没有更好的方法(比如 PHP 图像处理或者 CSS/Javascript)?
I'm trying to get it so, every time someone donates a set amount on a page, another equal portion of an image is revealed. I've got most of the other logic down (PayPal provides nice unique "you've donated" identifiers and such), however, I'm having trouble with revealing the image bit by bit.
I tried breaking up the image into small chunks (person wants at least 250 donations until the image is totally revealed), however, that doesn't work because of multiple formatting images. Is there any better way (say, PHP image processing or perhaps CSS/Javascript)?
发布评论
评论(3)
为什么不创建 251 个静态图像,每个付款级别一个,并根据迄今为止收到的资金比例动态提供正确的静态图像。
这似乎是最简单的方法,所需的唯一代码是查询付款级别,并将相关图像发送给客户端。
因此有一个
image0.jpg
(空)、image1.jpg
(一段)、image2.jpg
等等,最多image250.jpg
(所有片段),并让您的 Web 应用程序提供正确的服务。您需要确保这些图像在您网站的公共区域中无法访问,这样人们就无法找出 URL 并窃取您的“珍贵”。
因此,您的 Web 应用程序将收到对
images/image.jpg
的请求,查询应发送哪个图像,并使用实际图像的数据流进行响应,如下所示:Why don't you just create 251 static images, one for each payment level and serve the correct static image dynamically, based on the proportion of funds received to date.
This seems to be the simplest way of doing it, the only code required is to query the payment level, and send the relevant image down to the client.
So have a
image0.jpg
(empty),image1.jpg
(one segment),image2.jpg
and so on, up toimage250.jpg
(all segments), and have your web application serve the correct one.You'll need to make sure these images aren't accessible in the public area of your web site so people can't just figure out the URL and steal your "precious".
So, your web application will receive a request for
images/image.jpg
, query which image should be sent, and respond with the data stream from the actual image, something like:您可以将图像隐藏在
内,并将溢出设置为
hidden
。 然后,当您收到更多捐款时,只需将 div 元素调高即可。CSS:
You could hide the image inside a
<div>
, with overflow set tohidden
. Then you can simply make the div element higher as you recieve more donations.CSS:
最快的方法是使用 Google 图表 或 PayPal 的图片,看看是否可以进行调整到您的网站。 否则,您将需要动态生成图像或静态生成它们。 由于图像不是那么多,您也可以静态生成它们。
您可以使用多种工具来完成此操作,但 ImageMagick 可能是最通用的。 如果您想使用自己的图像,可以通过以下方法使用 ImageMagick 来实现。
您现在将拥有 256 个图像,如下所示:
(来源:theeggeadventure.com)
(来源:theeggeadventure.com)
(来源:theeggeadventure.com)
(来源:theeggeadventure.com)
显然,您可以调整几何形状或颜色以适应。
The quickest way would be to use Google Charts or PayPal's images and see if you can adapt one to your website. Otherwise, you're going to need to either generate the images dynamically, or statically generate them. Since it's not that many images, you may as well statically generate them.
You could do this with a number of tools, but ImageMagick is probably the most versatile. If you want to use you own image, here's how you could do it with ImageMagick.
You'll now have 256 images looking like this:
(source: theeggeadventure.com)
(source: theeggeadventure.com)
(source: theeggeadventure.com)
(source: theeggeadventure.com)
Obviously, you can adjust the geometry or colors to suit.