Speaking at FlashinTO v59.0
I'll be speaking at toronto's flash user-group next gathering.
It's a bit scary, as this is my first presentation.. I'll be doing a short version (20 minutes) of my presentation at FiTC about uploading, converting and distributing video using open-source components.
So, if you are in Toronto next Wednesday and you can't wait to see me screw up in front of an audience, or if you're just interested in the cheap beer, make sure your at the Resistor Gallery at Collage and Spadina. It's a little hard to find from the street, but if I recall correctly it's right next to a paint store.
Multi-file upload using SWFUpload
I heard a few times in the past about SWFUpload and recently I decided to try it out..
Basically SWFUpload is a 0x0 pixel swf that allows you to leverage Flash 8's upload mechanism through html/javascript. Not only can you let your users select multiple files to upload, it also allows you to catch the progress nicely, without a combination of nasty hacks with javascript, hidden frames and server-side callbacks.. It it distributed under the very permissive MIT license.
However, the integration went pretty bad.. SWFUpload is a very complete package and includes a big javascript wrapper, a bunch of examples and SWFObject, which is used to embed the object in the html using javascript and examples. For some reason it didn't work for me all, I assume there was probably some collision with my existing javascript.. and I don't really like SWFObject, as it has to my opinion overkill written all over it..
So, I peaked into the javascript, only to find out that just using the swf you have a lot of power already, you can specify your javascript callback functions straight from though the flashvars.. Neat! The flashvars look something like this:
<param name="FlashVars" value="uploadBackend=%2Fservices%2Fupload&uploadStartCallback=Uploader.onStart&uploadProgressCallback=Uploader.onProgress&uploadCompleteCallback=Uploader.onComplete&uploadCancelCallback=Uploader.onCancel&uploadErrorCallback=Uploader.onError&allowedFiletypes=%2A.gif%3B%2A.jpg%3B%2A.mp3&allowedFilesize=204800&uploadQueueCompleteCallback=Uploader.onQueueComplete" />
Very easy to use.. The only thing I really miss is the fact that selecting files and uploading is a combined step.. Not really handy in terms of usability..
My feature requests:
- Have a separate method for selecting files before upload.
- Allow the ability to replace the file upload list, but also append to the list.
- Have the callbacks return index numbers for the files.. Right now the only unique property you get is the filename, and there could be situations where 2 files with the same name are uploaded (rare, but still..).
- Implement a method for canceling the upload progress.
- Implement a method to remove a file from the upload queue.
The other problem I ran into using flash uploads are http cookie bugs.. I covered that in my last post.
Sharing sessions between html and flash
This has been an issue that has been driving me pretty crazy.. I can't seem to find out how to share a (cookie-)session between flash and php.
The problem is that in certain situations Flash ignores session cookies when sending requests. The situations I know of are Flash Uploads and using Flash Remoting in internet explorer.
I asked my question on #webappsec and on the web application security mailing list, but there wasn't really somebody who could answer my quesion..
Options
- I can pass the session id using flashvars directly. Problem with this is, is that the session id is directly embedded into the html and can therefore be stolen using CSRF.
- I can use a temporary token, but anybody who has this token can do everything the user can in the flash application. For just the uploads it can work, but for everything else its not really flexible, and doesn't really fix the problem.
- I could turn off httponly cookies and pass the session id using javascript straight to the flash movie.. This could be me only option, but I dislike it because its not as transparent as it should be and requires additional logic using javascript and flash (and php).
- Force the user to login when using flash.. Not really a nice solution from a usuability perspective..
I'm wondering how other people go about this.. Is there a satisfying solution at all? Or can it only be done using a combination of nasty hacks?
I'll be speaking at Flash in the Can 2007
It's confirmed! I get to speak at flash in the can 2007. This is great news for me, as I wanted to speak at tech conferences for a while now.. but finally I got in.
Flash in the can is a flash conference held in toronto for a few years now and it is one of the most important conferences in North America. It is actually the first tech conference I attended.
Irony is that I'm not that much into flash.. Much of my work is related to opensource and standards-based development, but in this area you can have a religion about technology, but in practice you have to set that aside for realism and pick the right tool for the job.
Currently flash is simply the number one way to bring video content to the browser in both user adoption and usability. I kind of rolled into the video thing by accident, because one of my earlier clients requested a user generated video application.. That ball kind of kept on rolling and developing video-enabled web applications has been my main role ever since.
The title of my presentation is Flash Video Lifecycle: From User To Delivery. I will be covering uploading using flash, handling uploads using php, converting with FFMpeg and delivering video using Flash.
I'm very excited, and hopefully I will be able to jumpstart and inspire the people who are into this sort of thing, but don't know where to start. If your there, be sure to say hi!
Rotating an image, retaining the original size
UPDATE: Ignore this post, this ranks number one in uselessness on my blog so far.. ImageRotate already does what I tried to achieve, and I didn't try it out, I just relied on a confusing line in the php manual.. For details : read pierre's response on this blog
.Here's a small code snippet which allows you to rotate images, while the dimensions are being retained (width becomes height, height becomes width).
The image argument should be an image handler, created by for example imagecreatefromjpeg(), or imagecreatetruecolor().
The rotation argument expects 0, 1, 2, 3, for 0 degrees, 90 degrees, 180 degrees or 270 degrees rotation. Unlike php's imagerotate function, this is clockwise..
<?php
function imageSmartRotate(&$image,$rotation) {
$width = imagesx($image);
$height = imagexy($image);
switch ($rotation) {
case 0 : return true;
case 2 : $image = imagerotate($image,180); return true;
case 1 :
case 3:
// checking the biggest coordinate (width or height)
$maxXY = $width>$height?$width:$height;
// create our new canvas
$rImg = imagecreatetruecolor($maxXY,$maxXY);
// copy our image
imagecopy($rImg,$image,0,0,0,0,$width,$height);
// rotate it (this function is counter clockwise (and counter intuitive))
$rImg = imagerotate($Img,(360-($rotate*90)),0);
// swap width/height
$h = $width;
$width = $height;
$height = $width;
// create the final canvas, with the proper dimensions
$image = imagecreatetruecolor($width,$height);
// if rotated 90 degrees the image will be in the bottom right corner
// if rotated 270 degrees the image will be in the top left corner
if ($rotate == 1) {
imagecopy($image,$rImg,0,0,$max-$width,$max-$height,$maxXY,$maxXY);
} else {
imagecopy($image,$rImg,0,0,0,0,$width,$height);
}
return true;
default :
return false;
}
}
?>
This method does take a bit more memory than usual, because it needs to create 2 other images of the same size to complete.. Are there more efficient ways to do this?







