Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #user uploads file and it moves to server
- move_uploaded_file ($_FILES['Image']['tmp_name'], "/sites/".$_FILES['Image']['name']) or die ('Could not upload');
- ?>
- <?php
- #create image path
- $img = imagecreatefromjpeg("/sites/".$_FILES['Image']['name']);
- ?>
- <?php
- #pixelate function
- #if($img && imagefilter($img,IMG_FILTER_PIXELATE,4))
- #{
- echo 'Win <br/>';
- imagejpeg($img,'image.jpg',100);
- ?>
- <?php
- #resize image
- $output_width =30;
- $output_height=50;
- $xytotal = $output_width*$output_height;
- $path = '/sites/image.jpg';
- $size_arr = getimagesize($path);
- if ($size_arr[2]==IMAGETYPE_GIF)
- $image = imagecreatefromgif($path);
- else if ($size_arr[2]==IMAGETYPE_JPEG)
- $image = imagecreatefromjpeg($path);
- else if ($size_arr[2]==IMAGETYPE_PNG)
- $image = imagecreatefrompng($path);
- else
- die_default_image();
- $tmpname = tempnam( sys_get_temp_dir() , "phptmp");
- resize_image($tmpname, $image, $size_arr, $output_width, $output_height);
- $img = imagecreatefromjpeg($tmpname);
- imagejpeg($img,'image.jpg',100);
- unlink( $tmpname );
- #loop to populate rgb values and save to array: $xy
- $imagew = imagesx($img);
- $imageh = imagesy($img);
- $xy = array(i);
- echo "Image (w,h): ($imagew, $imageh)<br/>";
- $x = 0;
- $y = 0;
- for ($x = 0; $x <= $imagew; $x++) {
- for ($y = 0;$y <= $imageh; $y++ ) {
- $rgb = imagecolorat($img, $x, $y);
- $r = ($rgb >> 16) & 0xFF;
- $g = ($rgb >> 8) & 0xFF;
- $b = $rgb & 0xFF;
- #loop to save ($r,$g,$b) into $xy
- for ($i = 0; $i <= $xytotal; $i++) {
- $xy[i] = ($r, $g, $b);
- }
- echo "xy: $xy x: $x, y: $y <br/>";
- var_dump($r, $g, $b);
- }
- }
- function die_default_image()
- {
- //43byte 1x1 transparent pixel gif
- header("content-type: image/gif");
- echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
- }
- function resize_image($thumbname, $image, $size_arr, $max_width, $max_height)//maintain aspect ratio
- {
- $width = $max_width;
- $height = $max_height;
- list($width_orig, $height_orig, $img_type) = $size_arr;
- $ratio_orig = $width_orig/$height_orig;
- if ($width/$height > $ratio_orig) {
- $width = floor($height*$ratio_orig);
- } else {
- $height = floor($width/$ratio_orig);
- }
- // Resample
- $tempimg = imagecreatetruecolor($width, $height);
- imagecopyresampled($tempimg, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
- imagejpeg($tempimg, $thumbname, 80);
- }
- if ( !function_exists('sys_get_temp_dir')) {
- function sys_get_temp_dir() {
- if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
- if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
- if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
- $tempfile=tempnam(uniqid(rand(),TRUE),'');
- if (file_exists($tempfile)) {
- unlink($tempfile);
- return realpath(dirname($tempfile));
- }
- }
- }
- ?>
- <br>
- <br>
- <img src="http://localhost/image.jpg" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement