Wednesday, 26 November 2014

stream_socket_client - Open Internet or Unix domain socket connection

resource stream_socket_client ( string $remote_socket [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") [, int $flags = STREAM_CLIENT_CONNECT [, resource $context ]]]]] )
Open Internet or Unix domain socket connection
Initiates a stream or datagram connection to the destination specified by remote_socket. The type of socket created is determined by the transport specified using standard URL formatting: transport://target. For Internet Domain sockets (AF_INET) such as T

<?php
$fp 
stream_socket_client("tcp://www.example.com:80"$errno$errstr30);
if (!
$fp) {
    echo 
"$errstr ($errno)<br />\n";
} else {
    
fwrite($fp"GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n");
    while (!
feof($fp)) {
        echo 
fgets($fp1024);
    }
    
fclose($fp);
}
?>


Tuesday, 25 November 2014

imagecopyresampled-Copy and resize part of an image with resampling

bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
Copy and resize part of an image with resampling
imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.

<?php// The file

$filename 'test.jpg';
$percent 0.5;// Content type
header('Content-Type: image/jpeg');// Get new dimensions
list($width$height) = getimagesize($filename);$new_width $width $percent;$new_height $height $percent;// Resample
$image_p imagecreatetruecolor($new_width$new_height);
$image imagecreatefromjpeg($filename);
imagecopyresampled($image_p$image0000$new_width$new_height$width$height);// Output
imagejpeg($image_pnull100);?>