Here is a class that I made a while back ... you can use it to resize your images.
<?php
class Image {
/** Class to control image functions */
var $source, $path;
function Image($source, $path){
$this->source = $source;
$this->path = $path;
}
function allowed(){
$allowed = array('image/jpg', 'image/jpeg', 'image/png');
if(in_array($this->source['type'], $allowed))
return true;
else
return false;
}
function returnSource(){
return print_r($this->source);
}
function dimensions(){
return getimagesize($this->path.$this->source['name']);
}
function upload(){
if(is_uploaded_file($this->source['tmp_name'])){
if(move_uploaded_file($this->source['tmp_name'], $this->path.$this->source['name']))
return true;
}
return false;
}
function resize($height = 300, $width = 400){
/** If array is not passed, use a variable */
$image = $this->path.$this->source['name'];
/** Create a blank image */
$resize = imagecreatetruecolor($width, $height);
$quality = 75;
$size = getimagesize($image);
switch ($size['mime']) {
case 'image/jpeg':
$im = imagecreatefromjpeg($image);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); // Resample the original JPEG
imagejpeg($resize, $image, $quality); // Output the new JPEG
break;
case 'image/jpg':
$im = imagecreatefromjpeg($image);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); // Resample the original JPEG
imagejpeg($resize, $image, $quality); // Output the new JPEG
break;
case 'image/png':
$im = imagecreatefrompng($image);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); // Resample the original PNG
imagepng($resize, $image, $quality); // Output the new PNG
break;
}
imagedestroy($im);
return true;
}
}
/** your code here **/
$img = array('name' => 'myImage.jpg', 'type' => 'image/jpg');
$path = '/home/username/public_html/images/';
/** create instance of the class **/
$class = new Image($img, $path);
/** resize image **/
$class->resize(300, 400);
/** end **/
?>