// John_Wild.Digital_Decomposition // This applet, created using processing [processing.org], downloads a photo of John Wild // Destroys 1 pixel // Sends the image back to the webserver and over wrights the original // The program uses the, Post To Web Library v0.6, created by seltar [http://libraries.seltar.org/postToWeb/] // johnwild.info import processing.pdf.*; import org.seltar.Bytes2Web.*; PDFToWeb pdf; PImage img; void setup() { size(520,768); // 520 x 768 = 394,160 pixels in the image. pdf = new PDFToWeb(this); String Iurl = "http://www.rupture.co.uk/auto-degeneration/saved/image/john-wild.jpg"; img = loadImage(Iurl); // Load the image from the web server into the program. noLoop(); } void draw() { image(img, 0, 0,520,768); // Displays the image color black = color(0,0,0); // Selects a random pixle int rand_width = int (random(width)); int rand_height = int (random(height)); //img.get(rand_width, rand_height); color c = img.get(rand_width, rand_height); // check pixel is not already black. if (c == black) { int i=0; while (i < 1) { rand_width = int (random(width)); rand_height = int (random(height)); // img.get(rand_width, rand_height); c = img.get(rand_width, rand_height); if (c != black) { i=2; } } } img.set(rand_width, rand_height, black); // Destroys random pixel image(img, 0, 0,520,768); // Displays the image pdf.addPage(); save_to_web(); } void save_to_web() // Sends the image back to the webserver and over rights the original { String url = "http://www.rupture.co.uk/auto-degeneration/Upload.php"; ImageToWeb img = new ImageToWeb(this); img.save("jpg",true); // Recomposed the image in jpeg file format. This will cause the image quality to deteriate. img.post("image",url,"john-wild",true,img.getBytes(g)); println("sending Image"); } ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // To make this code work you will also have to have the file upload.php // on your web server. // More info about this code at:- http://libraries.seltar.org/postToWeb/ // upload.php Source Code..... ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// \n"; $debugData .= "Other info given by browser (size, type): {$_FILES[$fieldName]['size']}, {$_FILES[$fieldName]['type']}
\n"; $fileSize = filesize($tempLocation); $debugData .= "Real file size: $fileSize
\n"; // Strangely enough, if IE is given a path leading to nowhere, it just sends a 0 byte file! if ($fileSize == 0) // Might test a minimum size (smallest header size for graphics...) { return array('', 'File is empty!'); } if ($fileSize > MAX_FILE_SIZE) { return array('', 'File too big!'); } // Get original file name $file = $_FILES[$fieldName]['name']; $debugData .= "Original file name: $file
\n"; // No HTML escape! :( // Strip out the path (given by IE, perhaps other browsers -- Firefox and Opera just give the name) // Most samples I saw use basename() but I found out that it fails to strip a Windows path on a Unix server // I could have used a str_replace, but I like REs... // (I gobble anything up to the last sequence of characters not having slash or anti-slash in it) // Note: ensure magic quotes are disabled or neutralized $file = preg_replace('!.*?([^\\/]+)$!', '$1', $file); $debugData .= "Filter 1: $file
\n"; // Filter out all characters that are not alphanumerical, dot and dash // as they can be troublesome in some OSes. // A sequence of such chars is replaced by a unique underscore. $file = preg_replace('/[^a-zA-Z0-9.-]+/', '_', $file); $debugData .= "Filter 2: $file
\n"; // Split name and extension: gobble everything up to the last dot (file name), then dot and remainder (extension) // Note that .htaccess has no extension and is a pure filename if (preg_match('/^(.+)\.([^.]+)$/', $file, $m) == 0) { // No match => No dot or nothing before the dot $extension = ''; } else { $file = $m[1]; $extension = $m[2]; } $debugData .= "Split: $file $extension
\n"; // Ensure name isn't too long: just truncate it $file = substr($file, 0, MAX_FILE_NAME_LENGTH); $debugData .= "Truncated: $file
\n"; // If extension not allowed (could be a CGI file...), discard it if ($extension != '' && !in_array($extension, $allowedExtensions)) { return array('', 'File format not allowed.'); } // Add trailing slash to dest dir, supposed in Unix format // (if not slash at end, replace last char by itself followed by a slash) $destinationDir = preg_replace('!([^/])$!', '$1/', $destinationDir); if(!file_exists($destinationDir)){ if(!mkdir_recursive($destinationDir, 0777)){ return array('', 'Cannot create project folder.' . " (dest.: $destinationDir)"); } chmod($destinationDir, 0777); } // Create a time stamp used as prefix to make the file name unique. // Might have a conflict if you have millions of users, ie. a probability of having two users // uploading a file in the same second, supposing they go in the same dir. // If so, you are able to improve this code! ;-) // One might want to pass a prefix (or suffix) parameter to this function, eg. to tag the file name // with the name of the author. Just do it! //$prefix = date('Ymd-His-'); //$prefix = ''; $destinationFile = $file . ($extension != '' ? '.' . $extension : ''); $debugData .= "Destination file: $destinationFile
\n"; $destinationPath = $destinationDir . $destinationFile; $debugData .= "Destination path: $destinationPath
\n"; // Move uploaded file from temporary folder to destination // Overwrite a file of same name there, if any (unless, perhaps server is on Windows, might just fail to move). // if (!file_exists($destinationFile)) // { if (!move_uploaded_file($tempLocation, $destinationPath)) { return array('', 'Failed to move upload file.' . " (dest.: $destinationPath)"); } chmod($destinationDir.$destinationFile, 0777); return array($destinationFile, $destinationPath); // } } else { return array('', 'Field not found'); } } function mkdir_recursive($pathname, $mode) { is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); return is_dir($pathname) || @mkdir($pathname, $mode); } $debugData = ''; // Get the title foreach($_FILES as $title=>$file){ break; } unset($file); // just to be sure $destDir .= $title.'/'; /* $maxFiles = 1000; // Max number of files accepted in the dest dir // First, check if we don't have too much files. Not a bad test: since we fix the max size of files, the max total size of the files // is under control. $files = @scandir($destDir); if(is_array($files)){ $files = array_slice($files, 2); // Shift out . and .. while (count($files) > $maxFiles) { $file = array_shift($files); echo $file . " to remove\n"; unlink($destDir . '/' . $file); } } */ $result = HandleUploadedFile($title, './'.$destDir, array('jpg', 'jpeg')); /* if ($debugData != '') { echo "

Debug data:
$debugData

\n"; } */ echo "

uploader

\n"; if ($result[0] == '') { echo "

Error: {$result[1]}

\n"; } else { $page="result.php"; $imageURL = 'http://' . $_SERVER['SERVER_NAME'] . $rootDir . $destDir . $result[0]; // echo $imageURL; } ?>