Skip to content

Commit

Permalink
trying to restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuckaby committed Mar 16, 2008
1 parent 0be5741 commit 9355254
Show file tree
Hide file tree
Showing 2 changed files with 381 additions and 0 deletions.
165 changes: 165 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.

"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.

An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.

A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".

The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.

The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:

a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or

b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the object code with a copy of the GNU GPL and this license
document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:

a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.

c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.

d) Do one of the following:

0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.

1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.

e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.

b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
216 changes: 216 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
JPEGCam v1.0

Webcam library for capturing JPEG images and submitting to a server
Copyright (c) 2008 Joseph Huckaby <jhuckaby@goldcartridge.com>
Licensed under the GNU Lesser Public License
http://www.gnu.org/licenses/lgpl.html

OVERVIEW

JPEGCam is a simple, JavaScript and Flash library that allows you to enable
your users to submit Webcam snapshots to your server in JPEG format. The
Flash movie is variable-sized, and has no visible user interface controls.
All commands sent to the movie are done so from JavaScript, so you can
implement your own look & feel on your site, create your own buttons, and
tell the Flash movie what to do from your own code.

REQUIREMENTS

JavaScript-enabled browser
Flash Player 9

EMBEDDING IN YOUR PAGE

(For a working example, see "test.html" in the htdocs folder.)

First, copy the following files to your web server:

webcam.js
webcam.swf
shutter.mp3

Next, edit your HTML and load the JavaScript library:

<script type="text/javascript" src="webcam.js"></script>

Configure a few settings (see API CALLS for complete list):

<script language="JavaScript">
webcam.set_api_url( 'test.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
</script>

Load the movie into the page. If you want to load the movie immediately,
simply use document.write() as shown below. If you are designing a DHTML
application, you can call webcam.get_html(...) at any time to dynamically
populate a DIV or other element after the page is finished loading.

<script language="JavaScript">
document.write( webcam.get_html(320, 240) );
</script>

Add some controls for sending commands to the movie (see API CALLS):

<br/><form>
<input type=button value="Configure..." onClick="webcam.configure()">
&nbsp;&nbsp;&nbsp;
<input type=button value="Take Snapshot" onClick="webcam.snap()">
</form>

Finally, add some code for handling the server response:

<script language="JavaScript">
webcam.set_hook( 'onComplete', 'my_callback_function' );
function my_callback_function(response) {
alert("Success! PHP returned: " + response);
}
</script>

That's it! See the following sections for a complete list of all the
available API calls, and how to write the server-side code.

API CALLS

Here are all the available API calls for the JPEGCam JavaScript library.
Everything is under a top-level global 'webcam' namespace.

webcam.set_hook( HOOK_NAME, USER_FUNCTION );

This allows you to set a user callback function that will be fired for
various events in the JPEGCam system. Here are all the events you
can hook:

onLoad
Fires when the Flash movie is loaded on the page. This is useful
for knowing when the movie is ready to receive scripting calls.

onComplete
Fires when the JPEG upload is complete.
Your function will be passed the raw output from the API script
that received the file upload, as the first argument.

onError
Fires when an error occurs. If this hook is not defined, the library
will display a simple JavaScript alert dialog. Your function will be
passed the error text as the first argument.

webcam.set_api_url( URL );

This allows you to set the URL to your server-side script that will
receive the JPEG uploads from the Flash movie. Beware of cross-domain
restrictions in Flash.

webcam.set_swf_url( URL );

This allows you to set the URL to the location of the "webcam.swf" Flash
movie on your server. It is recommended to keep this file in the same
directory as your HTML page, but if that is not possible, set the path
using this function. Beware of cross-domain restrictions in Flash.
The default is the current directory that your HTML page lives in.

webcam.set_quality( QUALITY );

This allows you to adjust the JPEG compression quality of the images
taken from the camera. The range is 1 - 100, with 1 being the lowest
quality (but smallest size files), to 100 being the highest quality
(but largest files). This does NOT control the resolution of the images,
only the JPEG compression. The default is 90.

webcam.set_shutter_sound( ENABLED );

This allows you to enable or disable the "shutter" sound effect that
the Flash movie makes when a snapshot is taken. Pass in a boolean
true or false to the function. It defaults to true.

Feel free to customize the sound effect by replacing the "shutter.mp3"
file with your own MP3 sound effect.

webcam.get_html( WIDTH, HEIGHT );

This returns the necessary HTML code to embed the Flash movie into your
page. Pass in the desired pixel width & height, which not only controls
the visual size of the movie, but also the JPEG image width & height.
Standard sizes are 320x240 and 640x480.

webcam.snap();

This instructs the Flash movie to take a snapshot and upload the JPEG
to the server. Make sure you set the URL to your API script using
webcam.set_api_url(), and have a callback function ready to receive
the results from the server, using webcam.set_hook().

webcam.configure( PANEL );

This launches one of Flash's configuration panels, used to setup camera
devices, privacy settings, and more. Pass in one of the following strings
which sets the default panel "tab" in the settings dialog:
"camera", "privacy", "default", "localStorage", "microphone", or
"settingsManager". Example:

webcam.configure( 'camera' );

SERVER-SIDE CODE

The Flash movie makes a HTTP POST to your server-side script, using the
Content-Type 'image/jpeg'. This is a NON-STANDARD method which is unlike
submitting a form from a web page. If you are using PHP, the JPEG data
will NOT be in the normal $_POST variable. Instead, it will be in a
global variable named:

$HTTP_RAW_POST_DATA

You can write this raw, binary JPEG data to a file handle using the PHP
function file_put_contents():

$filename = "my_file.jpg";
$result = file_put_contents( $filename, $HTTP_RAW_POST_DATA );

Any output from your script is passed back through the Flash movie to the
JavaScript code, which in turn passes it to your onComplete callback function.

For example, if you want your script to pass back a URL to the JPEG image,
save the file where you want it, and construct a URL to the file. Then simply
print the URL to the output like this:

(This assumes you are saving the files to the current working directory)

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI'])
. '/' . $filename;
print "$url\n";

(See "test.php" for a working example.)

FAQ

Q. I cannot see the image from my camera! What am I doing wrong?

A. You probably have to setup the camera device in the Flash Camera settings
dialog first. Often Flash doesn't auto-detect the right device.

webcam.configure( 'camera' );

It is always a good idea to provide a "Configure..." button on your
page which calls this function, so users can easily get to it.


Q. What is this ugly permission dialog? Can't I just make it remember me?

A. Yes, you certainly can! In the Flash setup dialogs, click on the 2nd icon
from the left (i.e. Privacy Settings), and you can click "Allow", then
check the "Remember" checkbox.

You can send your users directly to the Privacy config panel by calling:
webcam.configure( 'privacy' );

A cool trick is to detect "new" users (via a cookie) and register an onLoad
handler to send them directly to the Privacy settings.

webcam.set_hook( 'onLoad', 'my_load_handler' );
function my_load_handler() {
if (is_new_user())
webcam.configure( 'privacy' );
}

Of course, you have to write the is_new_user() function yourself.
I no wanna be settin' no cookies on your domain.

0 comments on commit 9355254

Please sign in to comment.