Jump to content

Recommended Posts

ok, I found this code somewhere and I am getting the errors

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/searls03/public_html/profile.php on line 35

 

Warning: imagefill() expects parameter 1 to be resource, boolean given in /home/searls03/public_html/profile.php on line 39. 

 

I can't seem to figure this out.  the website is http://www.kevinmusselman.com/2009/02/access-webcam-with-flash/

 

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/include_once "connect_to_mysql_1.php";

// Here we run a login check
if (!isset($_SESSION['username'])) { 
$inactivityTime = time() - 120; // 2 minutes
mysql_query("update `sessions` set `loggedin` = '0' where `activity` < '$inactivityTime' ");
   echo 'Please <a href="/login.php">log in</a> to access your account';
   exit(); 
}

//Connect to the database through our include 
// Place Session variable 'id' into local variable
$username1 = $_SESSION['username'];
$name1 = $_SESSION['name'];
/**
* Get the width and height of the destination image
* from the POST variables and convert them into
* integer values
*/
/**
* 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 white since I'm not sending 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
            // 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);
        }
    }
}
function genRandomString($length = 12) {
     $characters = '0123456789';
     $string ='';    


    for ($p = 0; $p < $length; $p++) {
         $string .= $characters[mt_rand(0, strlen($characters))];
     }

    return $string;

}
$bar =  genRandomString();
//This will create the file
$fp = fopen("images/".$username1."/".$username1."-".$bar.".jpg", "w");
ob_start();
imagejpeg($img, "", 90);
$img = ob_get_contents();
ob_end_clean();
fwrite($fp, $img);
exit;
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/246664-webcam/
Share on other sites

just had a quick look at the link you supplied. it is meant to post over the data. Make sure you have somethingn like firebug installed in your browser and follow the post request to make sure the variables are being passed.. also make sure the javascript is actually posting to the correct page

Link to comment
https://forums.phpfreaks.com/topic/246664-webcam/#findComment-1267293
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.