I have this Flash application that'd allow users to select
cliparts, enter text to create custom designs. At the end of the
process, I want them to be able to capture the design area and save
it as a JPEG file. I can get Flash to pass the pixel information of
the movie screen, but I can't figure out how to get CF to generate
the image on the receiving end. I searched online and found a
couple of PHP examples on dynamically generating JPEG files from
pixel information passed from Flash - is there a Coldfusion
equivalent of that? thanks in advance.Generate JPEG from Flash
I think you can do that using the Java BufferedImage class in
ColdFusion to create an image from the pixel array.
Check out:
http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/c6 d3f1dd0ba63258/964fad50af9d1e4%23964fad50af9d1e4
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferedImage.html
http://www.exampledepot.com/egs/javax.imageio/Graphic2File.html
Or you can try recreating the PHP logic in CF, which might be
easier if you are not comfortable working with Java in ColdFusion.
Generate JPEG from Flash
It looks like you can get interfaces to imagemagick in Java
and .NET. You could probably leverage either of those interfaces in
CF as well:
http://www.yeo.id.au/jmagick/
http://midimick.com/magicknet/
thanks! recreating PHP in CF might be the better choice.
below is the PHP code - is there a CF equivalent to
imagecreatetruecolor? thanks again!
%26lt;?php
error_reporting(0);
/**
* Get the width and height of the destination image
* from the POST variables and convert them into
* integer values
*/
$w = (int)$_POST['width'];
$h = (int)$_POST['height'];
// create the image with desired width and height
$img = imagecreatetruecolor($w, $h);
// now fill the image with blank color
// do you remember i wont pass the 0xFFFFFF pixels
// from flash?
imagefill($img, 0, 0, 0xFFFFFF);
$rows = 0;
$cols = 0;
// now process every POST variable which
// contains a pixel color
for($rows = 0; $rows %26lt; $h; $rows++){
// convert the string into an array of n elements
$c_row = explode('','', $_POST['px' . $rows]);
for($cols = 0; $cols %26lt; $w; $cols++){
// get the single pixel color value
$value = $c_row[$cols];
// if value is not empty (empty values are the blank pixels)
if($value != ''''){
// get the hexadecimal string (must be 6 chars length)
// so add the missing chars if needed
$hex = $value;
while(strlen($hex) %26lt; 6){
$hex = ''0'' . $hex;
}
// convert value from HEX to RGB
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
// allocate the new color
// N.B. teorically if a color was already allocated
// we dont need to allocate another time
// but this is only an example
$test = imagecolorallocate($img, $r, $g, $b);
// and paste that color into the image
// at the correct position
imagesetpixel($img, $cols, $rows, $test);
}
}
}
// print out the correct header to the browser
header(''Content-type:image/jpeg'');
// display the image
imagejpeg($img, '''', 90);
?%26gt;
I was a little worried about that - some of those PHP
functions don't exist in CF. At least not with the built in
functions. You might be able to find some User Defined Functions or
Custom tags out there to do that, but I'm guessing your best bet
might be to go down the JAVA route. In the meantime, you might want
to check out some of the other CF sites to see if someone has
already come across this problem. My recommendation would be eascfm
and houseoffusion.
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment