Can be used for many funny results
PHP Code:
<?php
# Mirror image
// mirrorimage.php?flip=1&url=http%3A%2F%2Fwww.google.com%2Fpress%2Fimages%2Fsergey_brin_lg.jpg
$type = $_GET['flip']; // 1 or 2
if(!$type) { $type = 2; }
$file = rand(0,20).'.jpg';
$fh = fopen("/tmp/".$file, "wb");
fwrite($fh, curl_get($_GET['url']));
fclose($fh);
$im = ImageCreateFromJpeg("/tmp/".$file);
if(!$im) { die("lol"); }
$mi = fliph($im);
if($type == 1) {
// make half of $mi transparent
$transparent = ImageColorAllocate($mi, 255,0,255);
imagefilledrectangle($mi, imagesx($mi)/2, 0, imagesx($mi), imagesy($mi), $transparent);
imageColorTransparent($mi, imagecolorexact($mi,255,0,255));
// combine them
$insert_x = imagesx($mi);
$insert_y = imagesy($mi);
imagecopymerge($im,$mi,0,0,0,0,$insert_x,$insert_y,100);
} else {
// make half of $mi transparent
$transparent = ImageColorAllocate($mi, 255,0,255);
imagefilledrectangle($mi,0, 0, imagesx($mi)/2, imagesy($mi), $transparent);
imageColorTransparent($mi, imagecolorexact($mi,255,0,255));
// combine them
$insert_x = imagesx($mi);
$insert_y = imagesy($mi);
imagecopymerge($im,$mi, 0,0,0,0,$insert_x,$insert_y,100);
}
// Echo image
header('Content-Type: image/png');
ImagePNG($im);
// Free RAM
ImageDestroy($mi);
ImageDestroy($im);
function fliph($im) {
$x_size = imagesx($im);
$y_size = imagesy($im);
$tmp = imagecreatetruecolor($x_size, $y_size);
$x = imagecopyresampled($tmp, $im, 0, 0, ($x_size-1), 0, $x_size, $y_size, 0-$x_size, $y_size);
if ($x) {
$im = $tmp;
return $im;
}
else {
die("Error!");
}
}
?>
<?php
# Function to get a file from an url using cURL
function curl_get($url) {
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($curl);
curl_close ($curl);
return $data;
}
# Function to write data to disk
function savefile($filename, $data) {
$fh = fopen("/tmp/$filename", "wb");
fwrite($fh, $data);
fclose($fh);
}
?>
Here's a file to make it easier to use, just put it in the same dir as mirrorimage.
PHP Code:
<html>
<head>
<title>
bbw
</title>
<body>
JPEG URL <form action="?" method="post"><input type="text" name="url" /> <input type="submit" value="mirror image"></form>
<img src="mirrorimage.php?flip=1&url=<?=urlencode($_POST['url']);?>"/><br />
<img src="mirrorimage.php?flip=2&url=<?=urlencode($_POST['url']);?>"/><br />
</body>
If it doesn't work you might have to turn up the memory limit in php.ini.
Here's a working example:
http://vestberg.net/~gommlem/flip.php 