iamali
01-10-2007, 06:01 PM
hey all!
i've been using flash to create an online graffiti wall and using PHP to create JPG images of images created on it but am having a bit of a problem. the JPGs are created fine but the colours are coming out wrong, see image below:
http://farm1.static.flickr.com/126/352712855_bccd09ca61.jpg (http://farm1.static.flickr.com/126/352712855_bccd09ca61_b.jpg)
it seems the red and yellow are coming out as blue and light blue. does anyone have any idea why this may be? this is the PHP code i am using:
<?php
//If GD library is not installed
if(!function_exists("imagecreate")) die("Sorry, you need GD library to run this example");
//Capture Post data
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
//Allocate image
$image = (function_exists("imagecreatetruecolor"))?imagecreatetruecolor( $width ,$height ):imagecreate( $width ,$height );
imagefill($image, 0, 0, 0xFFFFFF);
//Copy pixels
$i = 0;
for($x = 0; $x <= $width; $x++){
for($y = 0; $y <= $height; $y++){
while(strlen($data[$i]) < 6) $data[$i] = "0" . $data[$i];
$tmp = "0x" . $data[$i] ;
$data[$i] = sprintf("%x", $tmp - 0x1);
$r = 255-hexdec("0X".substr( $data[$i] , 0 , 2 ));
$g = 255-hexdec("0x".substr( $data[$i] , 2 , 2 ));
$b = 255-hexdec("0x".substr( $data[$i++] , 4 , 2 ));
$color = ($r << 16) | ($g << 8) | $b;
$color = imagecolorallocate($image, $r, $g, $b);
imagesetpixel ( $image , $x , $y , $color );
/*if ( ($r < 0 || $r >255) || ($g < 0 || $g >255) || ($b < 0 || $b >255) )
die("something");$ */
}
}
//Output image and clean
header( "Content-type: image/jpeg" );
ImageJPEG( $image );
imagedestroy( $image );
?>
This is the flash code I'm using:
import flash.display.BitmapData;
import flash.filters.DropShadowFilter
import flash.geom.Matrix;
preloader._visible = false
preview_btn.onPress = mx.utils.Delegate.create(this, previewDraw);
function previewDraw() { capture(1) }
//FUNCTION capture
function capture(nr){
snapshot = new BitmapData(500, 400);
snapshot.draw(_root, new Matrix());
var myDraw_mc:MovieClip = createEmptyMovieClip("snapshot_mc", 2);
myDraw_mc._x = 500;
myDraw_mc._y = 20;
myDraw_mc._xscale = 20;
myDraw_mc._yscale = 20;
myDraw_mc.attachBitmap(snapshot, 2);
var filterArray = new Array(myFilters[nr])
myDraw_mc.filters = filterArray
attachMovie("save_btn", "bot", 100, {_x:myDraw_mc._x+myDraw_mc._width+10, _y:myDraw_mc._y+myDraw_mc._height+10})
}
//FUNCTION output
function output(outputDraw){
preloader._visible = true
var pixels:Array = new Array()
var snap = new BitmapData(outputDraw.width, outputDraw.height);
myMatrix = new Matrix();
myMatrix.scale(0.5, 0.5)
snap.draw(outputDraw, myMatrix);
snap.applyFilter(snap, snap.rectangle, snap.rectangle.topLeft, myFilters[nr])
var w:Number = snap.width, tmp
var h:Number = snap.height
var a:Number = 0
this.onEnterFrame = function(){
for(var b = 0; b <= h; b++){
tmp = snap.getPixel32(a, b).toString(16)
pixels.push(tmp.substr(1))
}
perc = int((a * 100)/w)
preloader.perc.text = perc+" %"
preloader.barra._xscale = perc
a++
if(a>w){
preloader._visible = false
sendData(pixels, h, w)
snap.dispose()
delete this.onEnterFrame
}
}
}
//FUNCTION outputClip
function outputClip(outputDraw){
preloader._visible = true
var pixels:Array = new Array()
var snap = new BitmapData(outputDraw._width, outputDraw._height);
snap.draw(outputDraw);
var w:Number = snap.width, tmp
var h:Number = snap.height
var a:Number = 0
this.onEnterFrame = function(){
for(var b=0; b<=h; b++){
tmp = snap.getPixel32(a, b).toString(16)
pixels.push(tmp.substr(1))
}
perc = int((a*100)/w)
preloader.perc.text = perc+" %"
preloader.barra._xscale = perc
a++
if(a > w){
preloader._visible = false
sendData(pixels, h, w)
snap.dispose()
delete this.onEnterFrame
}
}
}
//FUNCTION sendData
function sendData(pixels:Array, h:Number, w:Number){
var output:LoadVars = new LoadVars()
output.img = pixels.toString()
output.height = h
output.width = w
output.send("show.php", "output", "POST")
}
stop()
thanks!
i've been using flash to create an online graffiti wall and using PHP to create JPG images of images created on it but am having a bit of a problem. the JPGs are created fine but the colours are coming out wrong, see image below:
http://farm1.static.flickr.com/126/352712855_bccd09ca61.jpg (http://farm1.static.flickr.com/126/352712855_bccd09ca61_b.jpg)
it seems the red and yellow are coming out as blue and light blue. does anyone have any idea why this may be? this is the PHP code i am using:
<?php
//If GD library is not installed
if(!function_exists("imagecreate")) die("Sorry, you need GD library to run this example");
//Capture Post data
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
//Allocate image
$image = (function_exists("imagecreatetruecolor"))?imagecreatetruecolor( $width ,$height ):imagecreate( $width ,$height );
imagefill($image, 0, 0, 0xFFFFFF);
//Copy pixels
$i = 0;
for($x = 0; $x <= $width; $x++){
for($y = 0; $y <= $height; $y++){
while(strlen($data[$i]) < 6) $data[$i] = "0" . $data[$i];
$tmp = "0x" . $data[$i] ;
$data[$i] = sprintf("%x", $tmp - 0x1);
$r = 255-hexdec("0X".substr( $data[$i] , 0 , 2 ));
$g = 255-hexdec("0x".substr( $data[$i] , 2 , 2 ));
$b = 255-hexdec("0x".substr( $data[$i++] , 4 , 2 ));
$color = ($r << 16) | ($g << 8) | $b;
$color = imagecolorallocate($image, $r, $g, $b);
imagesetpixel ( $image , $x , $y , $color );
/*if ( ($r < 0 || $r >255) || ($g < 0 || $g >255) || ($b < 0 || $b >255) )
die("something");$ */
}
}
//Output image and clean
header( "Content-type: image/jpeg" );
ImageJPEG( $image );
imagedestroy( $image );
?>
This is the flash code I'm using:
import flash.display.BitmapData;
import flash.filters.DropShadowFilter
import flash.geom.Matrix;
preloader._visible = false
preview_btn.onPress = mx.utils.Delegate.create(this, previewDraw);
function previewDraw() { capture(1) }
//FUNCTION capture
function capture(nr){
snapshot = new BitmapData(500, 400);
snapshot.draw(_root, new Matrix());
var myDraw_mc:MovieClip = createEmptyMovieClip("snapshot_mc", 2);
myDraw_mc._x = 500;
myDraw_mc._y = 20;
myDraw_mc._xscale = 20;
myDraw_mc._yscale = 20;
myDraw_mc.attachBitmap(snapshot, 2);
var filterArray = new Array(myFilters[nr])
myDraw_mc.filters = filterArray
attachMovie("save_btn", "bot", 100, {_x:myDraw_mc._x+myDraw_mc._width+10, _y:myDraw_mc._y+myDraw_mc._height+10})
}
//FUNCTION output
function output(outputDraw){
preloader._visible = true
var pixels:Array = new Array()
var snap = new BitmapData(outputDraw.width, outputDraw.height);
myMatrix = new Matrix();
myMatrix.scale(0.5, 0.5)
snap.draw(outputDraw, myMatrix);
snap.applyFilter(snap, snap.rectangle, snap.rectangle.topLeft, myFilters[nr])
var w:Number = snap.width, tmp
var h:Number = snap.height
var a:Number = 0
this.onEnterFrame = function(){
for(var b = 0; b <= h; b++){
tmp = snap.getPixel32(a, b).toString(16)
pixels.push(tmp.substr(1))
}
perc = int((a * 100)/w)
preloader.perc.text = perc+" %"
preloader.barra._xscale = perc
a++
if(a>w){
preloader._visible = false
sendData(pixels, h, w)
snap.dispose()
delete this.onEnterFrame
}
}
}
//FUNCTION outputClip
function outputClip(outputDraw){
preloader._visible = true
var pixels:Array = new Array()
var snap = new BitmapData(outputDraw._width, outputDraw._height);
snap.draw(outputDraw);
var w:Number = snap.width, tmp
var h:Number = snap.height
var a:Number = 0
this.onEnterFrame = function(){
for(var b=0; b<=h; b++){
tmp = snap.getPixel32(a, b).toString(16)
pixels.push(tmp.substr(1))
}
perc = int((a*100)/w)
preloader.perc.text = perc+" %"
preloader.barra._xscale = perc
a++
if(a > w){
preloader._visible = false
sendData(pixels, h, w)
snap.dispose()
delete this.onEnterFrame
}
}
}
//FUNCTION sendData
function sendData(pixels:Array, h:Number, w:Number){
var output:LoadVars = new LoadVars()
output.img = pixels.toString()
output.height = h
output.width = w
output.send("show.php", "output", "POST")
}
stop()
thanks!