Create new image
Posted: Sun Feb 12, 2006 6:00 pm
feyd | Please use
I'd appreciate any help,
b
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I have been having problems getting the imageJpeg() function to work and am not sure what's wrong. I've done a lot of research and (think that I) have (probably) ruled out character set and permissions conflicts by setting permissions to 777 and saving the files as western char. set.
However, What I am trying to do is use the gd functions to create thumbnails and then save as a new jpg. In other words, each time the create flv file runs (I'm using flash communications sserver in a separate but complementary ap) or plays for the first time, I want it to create a new jpeg from the flv.
I am basing (copying) my script off of Jorge Solis' and Sephiroth's tutorials and some comments I found at the php.net imagejpeg function and can't figure it out. Here's what it's doing (the front end was taken directly from J.Sollis' site (address un-remembered ) - my site is http://www.ahsodes.com/vidbb/flash/video/snapshot.html.
my [their] code:Code: Select all
<?php
error_reporting(1);
/**
* 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 < $h; $rows++){
// convert the string into an array of n elements
$c_row = explode(",", $_POST['px' . $rows]);
for($cols = 0; $cols < $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) < 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; charset=Western ISO-1");
// display the image
imagejpeg($img, "http://www.ahsodes.com/flash/video/mypic.jpg", 90);
imagedestroy( $image );
print("POST: ");
print_r($_POST);
?>I'd appreciate any help,
b
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]