Esempio n. 1
0
 /**
  *  Create a TCP Stream socket
  */
 function Server()
 {
     set_time_limit(0);
     $server_socket = socket_create(AF_INET, SOCK_STREAM, 0);
     $address = "127.0.0.1";
     /* Address will always be localhost for safety. */
     /* Bind the socket to an address/port */
     socket_bind($server_socket, $address, 0) or die('Could not bind to address');
     socket_getsockname($server_socket, $socket_address, $socket_port);
     debug("port: {$socket_port} \n");
     write_to_disk("port", $socket_port);
     /* Start listening for connections. */
     socket_listen($server_socket);
     while (true) {
         /* Forever handle clients. */
         /* Accept incoming requests and handle them as child processes. */
         $client_socket = socket_accept($server_socket);
         /* Create a new client which will do all the hard lifting. */
         new Client($client_socket, $server_socket);
     }
 }
Esempio n. 2
0
function image_preview($path_to_primary_image, $maximum_width)
{
    //Globalize appropriate variables.
    global $CONFIG, $lang_image_processor_php, $preview_image_directory;
    //Determine thumbnail method.
    $method = $CONFIG['thumb_method'];
    if ($method == 'gd2' and !function_exists('imageistruecolor')) {
        //Set ignore imageistruecolor to false.
        $ignore = 0;
    } else {
        //Set $ignore image is true color to true.
        $ignore = 1;
    }
    // Get image info.
    $source_image_size_and_type = cpg_getimagesize($path_to_primary_image) or die($lang_image_processor_php['file_corrupt']);
    $source_image_width = $source_image_size_and_type[0];
    $source_image_height = $source_image_size_and_type[1];
    $source_image_type = $source_image_size_and_type[2];
    //We need specify the path for the transitory file.
    // Create a prefix for easier human recognition.
    $prefix = "pre_";
    //Set the correct file extension.
    if ($source_image_type == '1') {
        $suffix = '.gif';
    } elseif ($source_image_type == '2') {
        $suffix = '.jpg';
    } elseif ($source_image_type == '3') {
        $suffix = '.png';
    }
    // Generate the unique name.
    do {
        $seed = substr(md5(uniqid('')), 0, 8);
        $path_to_preview_image = $preview_image_directory . $prefix . $seed . $suffix;
    } while (file_exists($path_to_preview_image));
    //Now we can upload the file.
    // Calculate dimensions.
    if ($source_image_width > $maximum_width) {
        $new_width = (int) $maximum_width;
        $new_height = (int) ($source_image_height * ($maximum_width / $source_image_width));
    } else {
        $new_width = $source_image_width;
        $new_height = $source_image_height;
    }
    //Begin processing if GD is used.
    if ($method == "gd2" or $method == "gd1") {
        // Get image handle
        $image_handle = get_handle($path_to_primary_image);
        // Create the destination image handle.
        if ($method == "gd2") {
            if ($ignore) {
                if (ImageIsTrueColor($image_handle)) {
                    $destination_image_handle = ImageCreateTrueColor($new_width, $new_height);
                } else {
                    $destination_image_handle = ImageCreate($new_width, $new_height);
                }
            } else {
                $destination_image_handle = ImageCreate($new_width, $new_height);
            }
        } elseif ($method == "gd1") {
            $destination_image_handle = ImageCreate($new_width, $new_height);
        }
        // Resize the image
        if ($method == "gd2") {
            //Use the higher quality function imagecopyresampled.
            imagecopyresampled($destination_image_handle, $image_handle, 0, 0, 0, 0, $new_width, $new_height, $source_image_width, $source_image_height);
        } elseif ($method == "gd1") {
            //Use the lower quality imagecopyresized.
            imagecopyresized($destination_image_handle, $image_handle, 0, 0, 0, 0, $new_width, $new_height, $source_image_width, $source_image_height);
        }
        //Destroy $image_handle
        imagedestroy($image_handle);
        // Write the image to disk.
        write_to_disk($source_image_type, $destination_image_handle, $path_to_preview_image);
        /*        if ($source_image_type == "2") {
        
        				imagejpeg($destination_image_handle, $path_to_preview_image) or die($lang_image_processor_php['no_write']);
        
        		} elseif ($source_image_type == "3") {
        
        				imagepng($destination_image_handle, $path_to_preview_image) or die($lang_image_processor_php['no_write']);
        
        		} elseif ($source_image_type == "1" && $CONFIG['GIF_support'] == 1) {
        				imagegif($destination_image_handle, $path_to_preview_image) or die($lang_image_processor_php['no_write']);
        		}
        
        // Destroy $destination_image_handle.
        imagedestroy($destination_image_handle); */
    } elseif ($method == "im") {
        // Set IM path.
        $im_path = $CONFIG['impath'];
        //Check the IM path for the final slash.
        if (eregi('/$', $im_path) or empty($im_path)) {
            $trailing_slash = "";
        } else {
            $trailing_slash = "/";
        }
        //Determine real paths to files.
        $real_path_to_primary_image = realpath($path_to_primary_image);
        $real_path_to_preview_image = realpath($path_to_preview_image);
        // Prevent the user from creating a process zombie by aborting while IM does its work.
        ignore_user_abort(true);
        // Issue the command for resizing to IM.  Have ImageMagick write the image to disk.
        $output = array();
        $cmd = "{$CONFIG['impath']}" . $trailing_slash . "convert -geometry {$new_width}x{$new_height} \"{$real_path_to_primary_image}\" \"{$real_path_to_preview_image}\"";
        exec($cmd, $output, $retval);
        // Restore the user abort setting.
        ignore_user_abort(false);
        if ($retval) {
            $ERROR = $lang_image_processor_php['IM_Error'] . $retval;
            if ($CONFIG['debug_mode']) {
                // Re-execute the command with the backtick operator in order to get all outputs
                // will not work is safe mode is enabled
                $output = `{$cmd} 2>&1`;
                $ERROR .= "<br /><br /><div align=\"left\">{$lang_image_processor_php['cmd_line']}<br /><span style=\"font-size:120%\">" . nl2br(htmlspecialchars($cmd)) . "</span></div>";
                $ERROR .= "<br /><br /><div align=\"left\">{$lang_image_processor_php['mog_said']}<br /><span style=\"font-size:120%\">";
                $ERROR .= nl2br(htmlspecialchars($output));
                $ERROR .= "</span></div>";
            }
            die($ERROR);
        }
    }
    return $path_to_preview_image;
}