Image upload quality issue

Not open for further replies.

I am trying to upgrade the quality of the images that are uploaded. I have it set up so that the images are uploaded and then resized and when the get resized they look terrible.

What are you using to resize the images? GD functions or Imagemagick ?
Just a .php code


class imagetweak extends dbroot {

function image_size_save($src_file, $src_url, $dest, $max_w, $max_h){

$image_src = $src_url.$src_file;

// ----------------------------------------------------------------
// Work on the Image Resizing

$image_size = getimagesize($image_src);
$image_src_width = $image_size[0];
$image_src_height = $image_size[1];

$x_ratio = $max_w / $image_src_width;
$y_ratio = $max_h / $image_src_height;

// Do Adjustments for image Size
if(($image_src_width <= $max_w) && ($image_src_height <= $max_h)){
$image_width = $image_src_width;
$image_height = $image_src_height;
elseif(($x_ratio * $image_src_height) < $max_h){
$image_height = ceil($x_ratio * $image_src_height);
$image_width = $max_w;
$image_width = ceil($y_ratio * $image_src_width);
$image_height = $max_h;
// ----------------------------------------------------------------
// Work on the Image Output

$src = $image_src;

$src = imagecreatefromjpeg($image_src);
$dst = imagecreatetruecolor($image_width, $image_height);

imagecopyresized($dst, $src, 0, 0, 0, 0, $image_width, $image_height, $image_src_width, $image_src_height);

// ----------------------------------------------------------------
// Print Out the Resulting Image

//header("Content-type: image/jpeg");
imagejpeg($dst, $src_url.$dest.$src_file, 100);


} // End Image_size_save Function

} //End class

Last edited:
The images are used online and we take the original files and use them for there ad in a printed magazine, that is why we keep the original.

I hope that was what you were asking.



if($access_info['reg_user'] != REG_KEY){ // If Not Logged in - No Access.
header("Location: /index.php");

// Report simple running errors
error_reporting (E_ERROR | E_WARNING | E_PARSE);

if (!session_is_registered('error')) {
$error = null;

// Check the form validation
$validator = & new formval;

if (!$validator->validate('text','yes',$userfile)) {
$error[image] = true;

//Test File Type & Size
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

//replace any chrs that may cause problems
$HTTP_POST_FILES['userfile']['name'] = str_replace (" ", "_", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("&", "_", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("?", "_", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("~", "_", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("'", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("@", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("!", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("#", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("$", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("%", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("*", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("(", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace (")", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("[", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("]", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("?", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("__", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = str_replace ("\\", "", $HTTP_POST_FILES['userfile']['name']);
$HTTP_POST_FILES['userfile']['name'] = strtolower ($HTTP_POST_FILES['userfile']['name']);

$filename = $HTTP_POST_FILES['userfile']['name'];
$filetype = $HTTP_POST_FILES['userfile']['type'];

$type_result = 0;
$filetype_array = array('image/jpg', 'image/jpeg', 'image/pjpeg'); // File Type Restrictions -> Others 'image/png', 'image/x-png', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif'
// File Restriction Posibilities
- 'image/jpg' // JPEG Image
- 'image/jpeg' // JPEG Image
- 'image/pjpeg' // JPEG Image PC
- 'image/gif' // GIF Image
- 'image/png' // PNG Image
- 'image/x-png' // PNG Image PC
- 'application/msword' // .doc
- 'application/pdf' // PDF Document
- 'text/plain' // Plain Text Document
- 'text/html' // HTML Document
- 'application/x-as' // ASP Documents .asp
- 'application/postscript' // Adobe Illustrator .ai
- 'application/octet-stream' // Photoshop .psd
- 'application/' // Excel Document on PC
foreach($filetype_array as $id => $result){
if($filetype == $result){
if($type_result == 0){ // If it's a restricted File Type, send it back with an error
$error[image_type] = $filetype;

$error[image] = true;

//Check for Duplicate Names
$image_match_obj = & new admin_images();
$image_match = $image_match_obj->get_image_match($vehicle_info['vehicle_id'], $filename);
//print "<pre>"; print_r($image_match); print "</pre>";

$error[img_dup] = true;

header("location: image_upload.php");

// Set some of the vars
$source_url = VEHICLES_DIR.$vehicle_info['vehicle_id']."/";

// save raw image to Vehicle Dir
move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $source_url.$filename);

// Take the raw image and Size Mag Mag Image to feature spec possibley Save space. Move that copy to the mag DIR
$image_size_obj = & new imagetweak();
$image_sized = $image_size_obj->image_size_save( $filename, $source_url, 'mag/', MAGFEAT_IMG_W, MAGFEAT_IMG_H );

// Take the raw image and Size Internet Image to pop-up spec Save that copy to the Int DIR
$image_size_obj = & new imagetweak();
$image_sized = $image_size_obj->image_size_save( $filename, $source_url, 'int/', INT_IMG_W, INT_IMG_H );

// Remove the raw image from the vehicle dir

// Check to see if there is an image that is already featured.
$image_feat_obj = & new admin_images();
$image_feats = $image_feat_obj->get_image_feature($vehicle_info['vehicle_id']);
$featured = 0;
$featured = 1;

// Add Image entries to db
$image_obj = & new admin_images();
$images = $image_obj->put_image( $vehicle_info['vehicle_id'], $filename, $featured, $caption );

header("location: /admin/vehicle.php?vid=".$vehicle_info['vehicle_id']."&action=edit&msg=Image Successfuly Uploaded.");
Is this it?
Well I am testing the script and it works fine. Thanks actually, you saved me the trouble of finding a similar one in case I need it :)

This is one of the images. Is it resized here or is it the original?

It looks good to me and also at the smaller sizes.

But the other images corresponding to the smaller thumbnails aren't good.

Is it possible some of the uploaded images aren't that good?
Last edited:
OK the script makes on size of images to go into the folder int (with maximum dimensions INT_IMG_W, INT_IMG_H) and another size of images to go into the folder mag ( with maximum dimensions: MAGFEAT_IMG_W, MAGFEAT_IMG_H ) - or so I figure it out.

I don't know what your dimensions are for each of mag and int and what size picture you start with.
We start with a image that was shot off a digital camera, about 14in x 240 dpi
How does that compare dimension-wise to the 2 sizes of images you show on that page? Those are 360px X 270px and somehting smaller like about 100px X 80px or so.

And more importantly - when you inspect the originals of those 3 images, can you see 2 of them as being worse in quality at their full size than the other one?
I just messed with one of them I am sorry about that. The aspect ratio stays the same from the original file (or should). The thumbnails are actually the same image as the smaller ones but constrained
Matt, the image called 2cl55.jpg is a huge file, 2.1MB and a huge image: 1867 x 1400 pixels. A bit shaky.

2cl55-Original.jpg is small, 38K , 360 x 270 pixels and quite shaky.

2cl55-DesiredQuality.jpg is smaller, 32K, also 260 x 270 pixels and pretty good, the shakiness is not very visible.

All 3 appear to be 300dpi - but this doesn't men anything right away.

I am wondering what the actual order of images is here. I can't see the file called Original being the actual original. If anything it's the worst of the lot.

I will have to assume 2cl55.jpg is the actual original, and the one called Original would have to actually be the result of the resizing by that script.

If that's not the case then ... it means you are using the script to make a much bigger file than what you started out with - and that would of course make the quality worse.

Unless when you emailed you accidentally instructed the email client to reduce some images for email.....
Not open for further replies.