This code works correctly when it is all put together, except for the image size, it should resize to 50%, but when I add in my function, it doesn’t resize it, but rotating it works. If I remove the function, then resizing does work, so where and how would I insert it?
OK… I have this code:
[code=php]<?php
// The file
session_start();
$img_id = $_GET[‘image_id’];
include”db.php”;
$img = mysql_query(“SELECT * FROM files where file_id=’$img_id'”)or die(mysql_query());
$imgs = mysql_fetch_array($img);
$filename = “users/”.$_SESSION[‘user’].”/$imgs[file_name]”;
#$filename = “users/ryan/screen2.jpg”;
//$filename = ‘images/user_images/geoff.jpg’;
$percent = .5;
function getext($file) {
$pos = strrpos($file,’.’);
$str = substr($file, $pos);
return strtolower($str);
}
// Content type
if(getext($filename)==’.jpg’){
header(‘Content-type: image/jpeg’);
}elseif(getext($filename)==’.gif’){
header(‘Content-type: image/gif’);
}elseif(getext($filename)==’.png’){
header(‘Content-type: image/png’);
}
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
if(getext($filename)==’.jpg’){
$source = imagecreatefromjpeg($filename);
#$source = rotate($filename,$_GET[‘degrees’]);
//$thumb = rotate($source,$_GET[‘degrees’]);
}elseif(getext($filename)==’.gif’){
$source = imagecreatefromgif($filename);
}elseif(getext($filename)==’.png’){
$source = imagecreatefrompng($filename);
imageAlphaBlending($source, true);
imageSaveAlpha($source, true);
}
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
if(getext($filename)==’.jpg’){
imagejpeg($thumb);
}elseif(getext($filename)==’.gif’){
imagegif($thumb);
}elseif(getext($filename)==’.png’){
imagepng($thumb);
}
?>
I want to add this function, so I add it to the top.
[code=php]function rotate($filerotate,$rotationamount){
// File and rotation
$filename = $filerotate;
$degrees = $rotationamount;
// Content type
header(‘Content-type: image/jpeg’);
// Load
$source = imagecreatefromjpeg($filename);
// Rotate
$rotate = imagerotate($source, $degrees, 0);
// Output
return imagejpeg($rotate);
}
My question is… Where do I add this:
[b]$thumb = rotate($source,$_GET[‘degrees’]);
I don’t know if [b]$source[b]$thumb[b]$_GET[‘degrees’]
If you need more Information, please ask.