views:

183

answers:

3

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)?

A: 
brianegge
He doesn't put any levels in the URL and in fact he offers an excellent complement to Pax's solution: brianegge's solution will generate the 251 images Pax's solution required. +1.
Josh
A: 

You could hide the image inside a <div>, with overflow set to hidden. Then you can simply make the div element higher as you recieve more donations.

<div id="imageContainer">
   <img src="secretImg.jpg"/>
</div>

CSS:

#imageContainer {
   height: 20px;
   overflow: hidden;
}
peirix
Pretty easy to see the secret image though.
Rich Bradshaw
Yeah, I know. But I wasn't sure _how_ secret the image was supposed to be. If it was only for fun sake to hide part of the image, then this would work. But if the goal is to make the users want to donate to be able to see the whole image, then this would be a bad idea.
peirix
+1 to counteract the negative. This is actually a fine answer, as long as the fact that it is woefully insecure is understood.
SamGoody
@samgoody, you should probably +1 brianegge's answer as well :-) But seriously, if the intent is to make a certain amount of money by not revealing content until you have it, woefully insecure is not really the way to go.
paxdiablo
+3  A: 

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 to image250.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:

if actual > desired:
    number = 250
else:
    number = int (actual * 250 / desired)
imagename = "image" + str(number) + ".jpg"
paxdiablo
Hey, that might actually work pretty well. Sometimes you never think of the simplest things. :) Possible best answer for you.