I have a slight problem that I am hoping you can help me with. I have a PHP page that recieves info from Flash via POST, and use that info to process and resize an image. Here's where the problem comes in... I want to send the path for the newly processed image back to Flash for display, but in order to do that, I need a path. So my question is this. Does anyone know of a way to send the path back to flash without ever having to actually write the new file to my server? I'm really hoping to avoid doing that, if possible. Here's the PHP code I am using:
Code: Select all
<?php
// Incoming data via Post
$imageName = $_POST['imageName'];
$imageSizeX = $_POST['imageSizeX'];
$imageSizeY = $_POST['imageSizeY'];
$maxX = 120;
$maxY = 112;
$image = open_image($imageName);
if ($image === false) {
die('Unable to open image');
}
$oldX = $imageSizeX;
$oldY = $imageSizeY;
function open_image($file) {
# JPEG:
$im = @imagecreatefromjpeg($file);
if ($im !== false) { return $im; }
# GIF:
$im = @imagecreatefromgif($file);
if ($im !== false) { return $im; }
# PNG:
$im = @imagecreatefrompng($file);
if ($im !== false) { return $im; }
# GD File:
$im = @imagecreatefromgd($file);
if ($im !== false) { return $im; }
# GD2 File:
$im = @imagecreatefromgd2($file);
if ($im !== false) { return $im; }
# WBMP:
$im = @imagecreatefromwbmp($file);
if ($im !== false) { return $im; }
# XBM:
$im = @imagecreatefromxbm($file);
if ($im !== false) { return $im; }
# XPM:
$im = @imagecreatefromxpm($file);
if ($im !== false) { return $im; }
# Try and load from string:
$im = @imagecreatefromstring(file_get_contents($file));
if ($im !== false) { return $im; }
return false;
}
header("Content-type: image/jpeg");
if ($oldX > $oldY) {
$percent = ($maxX/$oldX);
$newX = $oldX*$percent;
$newY = $oldY*$percent;
$image_resized = imagecreatetruecolor($newX,$newY);
$newImage = imagecopyresampled($image_resized,$image,0,0,0,0,$newX,$newY,$oldX,$oldY);
} else {
$percent = ($maxY/$oldY);
$newX = $oldX*$percent;
$newY = $oldY*$percent;
$image_resized = imagecreatetruecolor($newX,$newY);
$newImage = imagecopyresampled($image_resized,$image,0,0,0,0,$newX,$newY,$oldX,$oldY);
}
$newImage = imagejpeg($image_resized);
die();
?>
?>