codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php if(isset($argc) && (!isset($_GET) || empty($_GET))){ for($i = 1; $i < $argc; ++$i){ if(strpos($argv[$i], '--') === 0){ $argv[$i] = substr($argv[$i], 2); } list($key, $value) = explode('=', $argv[$i], 2); $_GET[$key] = $value; } } if(!isset($_SERVER['DOCUMENT_ROOT']) || $_SERVER['DOCUMENT_ROOT'] == ''){ $_SERVER['DOCUMENT_ROOT'] = /* ... */; } if(isset($_GET['img'])){ $name = urldecode($_GET['img']); }else{ die('unspecified'); } $pipe_name = realpath("{$_SERVER['DOCUMENT_ROOT']}/lib/php/pipes") . "/$name"; if(!file_exists($pipe_name) && !posix_mkfifo($pipe_name, 0777)){ file_put_contents('output', 'Pipe could not be created.'); exit(1); } $pipe = fopen($pipe_name, 'r+'); if(!$pipe){ file_put_contents('output', 'Pipe could not be opened.'); exit(1); } function pipe($msg, $die=FALSE){ global $pipe; fwrite($pipe, $msg . PHP_EOL); if($die){ die($msg); }else{ echo $msg; } } $w = 150; $h = 114; if(!file_exists($image = $_SERVER['DOCUMENT_ROOT'] . '/images/' . $name)){ pipe('invalid', TRUE); } $cache = $_SERVER['DOCUMENT_ROOT'] . '/thumbs/' . $name; if(!file_exists($cache)){ $thumb = new Imagick($image); $thumb->flattenImages(); $quotient = min($thumb->getImageWidth() / $w, $thumb->getImageHeight() / $h); $thumb->cropImage($w * $quotient, $h * $quotient, 0, 0); $thumb->scaleImage($w, $h); // $thumb->writeImage($cache); } pipe('success'); fclose($pipe); ?>
Private
[
?
]
Run code
Submit