
Real-time GIF images - erikvdven
http://github.com/ErikvdVen/php-gif
======
donatj
Motion JPEG is arguably better suited to the task as the browser knows not to
cache the previous frames by rule. It's actually designed for this exact
purpose.

I made a little example project a few years back. The format is dead simple,
keep the connection open, flush multiple JPEGS separated by a header. It's
used pretty often by cheap security cameras and is supported by most browsers.
It just seems to be not widely known about.

[https://github.com/donatj/mjpeg-php](https://github.com/donatj/mjpeg-php)

~~~
nacs
I've found MJPEG to be more bandwidth intensive, especially as the resolution
increases however, since its flushing the full frame every time (whereas with
GIF you could send just the differences between frames).

~~~
donatj
Would depend on what you're sending. If you take make good advantage of gif
interframe transparency and are just sending small updates the result could be
very small. That still leaves the problem unless I'm mistaken of the browser
hanging on to the old gif frames.

~~~
tcdent
Are you saying that retention is bad from a memory use perspective, or that
there is a risk of looping mid-broadcast?

~~~
donatj
Memory use. If it thinks it might finish and need to loop it would hold on to
all the frames it's received.

------
skimmas
I believe gmail caches all the images so that leaves out a huge amount of the
world maiboxes.

~~~
jeffjose
You're right. Google changed the way they did images a while back to prevent
email image marketers who used to track when the user opened an email using a
1pixel transparent image downloads.

~~~
andreyf
"1x1 transparent pixel" is called a "tracking pixel".

Gmail still allows marketers to track when a user opens an email (even better
than before, since it no longer asks users whether they want to load images).
However, they proxy the request so that the tracking pixel host no longer gets
the user's IP address or third party cookies.

~~~
nileshtrivedi
Where can I read more about this? Doesn't this help spammers? I thought I was
safe if I disable auto-loading of images!

~~~
ZoF
You're safe either way, but if you have autoloading disabled they still can't
track that you've read until you load the images.

The change is that clicking to load images is no longer the default [0]

Do you get enough spam on your Gmail for this to be a worry point? Genuinely
curious; I get roughly zero.

[0][http://www.wired.com/2013/12/turn-gmail-auto-image-
loading-o...](http://www.wired.com/2013/12/turn-gmail-auto-image-loading-off/)

~~~
noja
> You're safe either way

Eh? Before they used track-me.example.com/IDHERE and got blocked, now they use
IDHERE.track-me.example.com and don't get blocked.

Move the unique ID to DNS and Google will let it through.

~~~
ZoF
I assumed by safe you meant something else.

Yes if you load images they can track that you have opened the email.

I fail to see how that is 'unsafe' though. It's expected functionality.

~~~
noja
It's expected that they can track you, when before they blocked the images to
prevent that?

------
tcdent
I'm mildly baffled by the coding style of the main encoder class[0]; where do
these conventions come from?

(All-caps three character properties, namespaced(?) arguments, spaces e v e r
y w h e r e, curly bracket array access.)

Also, I didn't know `class` and `array` were case-insensitive.

[0] [https://github.com/ErikvdVen/php-
gif/blob/master/GIFEncoder....](https://github.com/ErikvdVen/php-
gif/blob/master/GIFEncoder.class.php)

~~~
viraptor
Comments say it's based on this:
[https://github.com/demouth/DmImage/blob/master/example/sampl...](https://github.com/demouth/DmImage/blob/master/example/sample_node/animate/GifMerge.class.php)

Some of what you mentioned is already present there. Some other things are
new. But they're both terrifying...

Extra details: the rewrite into gifencoder happened in 2007, so gifmerge must
be older than that (maybe 4.x times). The original license forbids modifying
gifmerge without author's approval - since this file doesn't mention it at
all, I doubt dmimage is legal.

~~~
otakucode
> But they're both terrifying...

Welcome to PHP! Truly the language which most directly represents the soul of
the web - a stateless static documentation presentation system which we
shoehorn application functionality into regardless of the pain!

------
anewhnaccount
This is better:
[https://github.com/videlalvaro/gifsockets](https://github.com/videlalvaro/gifsockets)
\- it's event based so doesn't tie up lots of memory while running and doesn't
stop after 30 frames.

~~~
andreyf
Oh, this is actually neat:

> what about progress bars for stuff that your server is doing in the
> background

This seems like a really good micro-service.

------
jacquesm
Funny how we go full-circle. This is roughly the way I did live video in '95.

~~~
amelius
I don't think it is really funny. Hacks like this is how progress is delayed.
Because why innovate when you can rely on "hacks that provably work in the
real world"?

~~~
Kristine1975
This hack is an innovation in its own right. And it should work with most
browsers, contrary to completely new technology.

~~~
jacquesm
Well, it _was_ innovation 20 years ago. Today there are more direct ways that
achieve the same effect (such as canvas) without taking these roundabout ways.

~~~
boxidea
Good luck finding an email client that supports canvas.

~~~
jacquesm
Good luck finding an email client that will load animated gifs from remote
sources _and_ will keep the connection open indefinitely. Personally I'd
consider either one of those to be a bug worthy of a ticket.

------
oakwhiz
The only issue with this kind of hack is that it uses a lot of bandwidth
continuously, as long as the image exists. I wouldn't exactly consider GIF to
be a good compression format for live streaming.

This might not be an issue for users on broadband internet connections, but on
low bandwidth, metered cell phone networks, and congested Wifi networks, this
could cause issues (such as slowdowns or unintentionally using up your metered
bandwidth allocation) that wouldn't be nearly as bad if a piece of Javascript
was used to live-update a page instead.

I wonder if it would be possible to make a live WebM version of this instead.

~~~
witty_username
Additionally, GIF has only 256 colors.

~~~
geographomics
Only 256 colours per frame, but they don't have to be the same ones, and can
be combined to use a wider palette - for example:
[http://notes.tweakblogs.net/blog/8712/high-color-gif-
images....](http://notes.tweakblogs.net/blog/8712/high-color-gif-images.html)

------
0xcde4c3db
This reminds me of an IOCCC entry (further details elided; read the hint file
if you want it "spoiled") [1]

[1] IOCCC 2013 winner, most timely rendered:
[http://www.ioccc.org/2013/mills/](http://www.ioccc.org/2013/mills/)

------
biot
Netscape did a similar thing to this in 1994 with their Fishcam, converting
frames from a video capture and served up as new frames of a GIF image. It was
eventually shut down in 2007 and the original developer[0] setup a dedicated
site for it: [http://www.fishcam.com/](http://www.fishcam.com/)

Nice to see the forgotten technology repurposed.

[0] [http://www.montulli.org/lou](http://www.montulli.org/lou)

------
niftyimages
Great bit of source code. We've taken a similar approach to create free timers
for email marketers.

[https://niftyimages.com/TryIt/Timers](https://niftyimages.com/TryIt/Timers)

------
scottydelta
Well a good way to troll. You send an image to someone in the email and then
change the image once the person forwards this email to others.

~~~
fudged71
not just trolling but could also be used for social engineering...

~~~
Herrera
You are right. You receive one image containing a inspirational message for
your family and decide to send to your family members. Then it changes to a
image asking for money to be sent to an account because you are in need. I
could see this working.

------
swanson
Funny coincidence -- I just received an email with a countdown like that today
and was very curious. In my case, the email was using:
[https://www.realtime.email/](https://www.realtime.email/)

~~~
erikvdven
Now you can do it yourself haha ;) I still have to cleanup the code a bit.
Thinking of creating a class which allows you to create such image by just
writing a multidimensional array, so less code to write. But I couldn't wait
to share this already so... But updates are coming soon.

------
ai233
Intriguingly, I've been thinking about exactly the same thing recently.

------
ishener
why not go to the next level and do Real-time video generation:
[https://pv.idomoo.com/](https://pv.idomoo.com/)

~~~
erikvdven
Well, the purpose of the code is to use it in mail clients. And because mail
clients don't allow you to use javaScript and such, using an image is the most
obvious alternative.

------
DaGardner
from the source code: "Updated at 2007. 02. 13. '00.05.AM'"

~~~
JosephRedfern
Urmm, going by the filename ("GIFEncoder.class.php"), that's just the GIF
Encoder. This post isn't about the ability to generate GIFs using PHP (as that
class does), but about varying the content of the GIF on a per-request basis
(in "real-time").

Looking at the git commit history, this was created ~2 days ago.

------
kmfrk
PHP. On my Hacker News? :)

------
popmystack
I am confused? How is this being upvoted? This kind of project has been a
staple in the programming community from gaming to forums for two decades now.

~~~
andreyf
It has? Can you give an example?

This is generating a custom GIF file on the server. It's most likely been done
by someone somewhere before, but not something I've been both gaming and
forum-ing for a little while.

~~~
pluma
This is roughly how early webcams worked. So, it's indeed not novel.

