Jump to content

Saving Modified Image to Server


vital101

Recommended Posts

Hey everyone,

 

I'm trying to take a image that is server side, resize it, and then save it another location server side.  I've gotten to the point where I save the image, but I don't know how.  Any ideas?

 

<?php
include('image_scale_functions.php');
$image = open_image('flower.jpg');

if ($image === false) {
		die ('Unable to open image');
}

$width = imagesx($image);
$height = imagesy($image);

echo "Opened Image";
echo 'Height: ' . $imageY . ' pixels';
echo 'Width: ' . $imageX . ' pixels';

if($width > 110) {
	$ratio = 110 / $width;
	$new_width = 110;
	$new_height = (int)($height * ratio);

	// Resample
	$image_resized = imagecreatetruecolor($new_width, $new_height);
	imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
}

?>

 

/vital101

Link to comment
https://forums.phpfreaks.com/topic/101949-saving-modified-image-to-server/
Share on other sites

<?php
include('image_scale_functions.php');
$image_name = "flower.jpg";
$image = open_image($image_name);

if ($image === false) {
		die ('Unable to open image');
}

$width = imagesx($image);
$height = imagesy($image);

echo "Opened Image";
echo 'Height: ' . $imageY . ' pixels';
echo 'Width: ' . $imageX . ' pixels';

if($width > 110) {
	$ratio = 110 / $width;
	$new_width = 110;
	$new_height = (int)($height * ratio);

	// Resample
	$image_resized = imagecreatetruecolor($new_width, $new_height);
	imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                $output = "whatever was returned from imagecopyresampled";
	$new_image = $image_name."_resized.jpg";
	$new_file = fopen($new_image, "+w");
	fwrite($new_file, $output);
	fclose($new_file);
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.