So i created an image resizing script, and am having trouble saving the resized image to the server.
imagejpeg($image_resized, $imagelocation);
should save the image to where i designate $imagelocation as, but it doesn't. Should i use fopen instead? Also, is there any way i can make it so this script scan folders and apply the script to certian files in them?
[RIGHT]Thanks, Dan[/RIGHT]
<?php
//dan's lame image resizer
// Load image
$image = open_image('flower.jpg');
if ($image === false) { die ('Unable to open image'); }
// Get original width and height
$width = imagesx($image);
$height = imagesy($image);
//echo 'Height: ' . imagesy($image) . ' pixels';
//echo 'Width: ' . imagesx($image) . ' pixels';
// Set a new width, and calculate new height
$new_width = 200;
$new_height = $height * ($new_width/$width);
// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Display resized image
$imagelocation = 'resizedflower.jpg'
header('Content-Type: image/jpeg');
imagejpeg($image_resized, $imagelocation);
die();
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;
}
?>