Getting the path of resized images...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nyghtrunner
Forum Newbie
Posts: 6
Joined: Fri Jul 13, 2007 3:11 pm

Getting the path of resized images...

Post by nyghtrunner »

Hey all,

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();
			
?>		
?>
If anyone has any suggestions on how I might be able to save a path (even a temporary one!) to a variable to pass back to flash, I promise to bake you cookies!!! :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Either actually save the file or send back the binary data instead of a path.
Post Reply