Jump to content

creating a basic thumbnail


unistake

Recommended Posts

Hi all,

 

I have been looking at thumbnail scripts and they are all very advanced for what I want.

 

I just want to take 3 uploadeed jpg images, save a copy in original format and save a copy in images/thumbs/ with a size of 200px x 133px.

 

Could someone just show me who to do this?

 

Thanks

 

The script I have for uploading the actual image is:

 

<?php

	$destination='aircraft/'.$reg."1.jpg";
	$temp_file = $_FILES['image']['tmp_name'];
	move_uploaded_file($temp_file,$destination);
	$destination2='aircraft/'.$reg."2.jpg";
	$temp_file2 = $_FILES['image2']['tmp_name'];
	move_uploaded_file($temp_file2,$destination2);
	$destination3='aircraft/'.$reg."3.jpg";
	$temp_file3 = $_FILES['image3']['tmp_name'];
	move_uploaded_file($temp_file3,$destination3);

?>

Link to comment
Share on other sites

Thanks for that.

 

I have been trying to use it today but can not get it to work. The code I have is:

Can anyone see anything wrong with it? I have put a note next the the part where I think I am going wrong.

 

<?php
$destination='aircraft/'.$reg."1.jpg";
	$temp_file = $_FILES['image']['tmp_name'];
	move_uploaded_file($temp_file,$destination);
	$destination2='aircraft/'.$reg."2.jpg";
	$temp_file2 = $_FILES['image2']['tmp_name'];
	move_uploaded_file($temp_file2,$destination2);
	$destination3='aircraft/'.$reg."3.jpg";
	$temp_file3 = $_FILES['image3']['tmp_name'];
	move_uploaded_file($temp_file3,$destination3);

	// THUMBNAIL PROCESS

	$file = $_FILES['image']['name'];  
	$save = $reg.'1.jpg';
	$t_w = 200;
	$t_h = 133;
	$o_path = " ";  // NOT SURE WHAT THIS COULD BE.
	$s_path = "aircraft/thumbs/";

	Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { 
    $s_path = trim($s_path); 
    $o_path = trim($o_path); 
    $save = $s_path . $save; 
    $file = $o_path . $file; 
    $ext = strtolower(end(explode('.',$save))); 
    list($width, $height) = getimagesize($file) ;  
    if(($width>$t_w) OR ($height>$t_h)) { 
        $r1 = $t_w/$width; 
        $r2 = $t_h/$height; 
        if($r1<$r2) { 
          $size = $t_w/$width; 
        }else{ 
          $size = $t_h/$height; 
        } 
    }else{ 
        $size=1; 
    } 
    $modwidth = $width * $size;  
    $modheight = $height * $size;  
    $tn = imagecreatetruecolor($modwidth, $modheight) ;  
    switch ($ext) { 
        case 'jpg': 
        case 'jpeg': 
                    $image = imagecreatefromjpeg($file) ;  
        break; 
        case 'gif': 
                    $image = imagecreatefromgif($file) ;  
        break; 
        case 'png': 
                    $image = imagecreatefrompng($file) ;  
        break; 
    } 
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;  
    imagejpeg($tn, $save, 100) ;  
    return; 
} 
?>

Link to comment
Share on other sites

Try this

 

<?php
$destination='aircraft/'.$reg."1.jpg";
$temp_file = $_FILES['image']['tmp_name'];
move_uploaded_file($temp_file,$destination);
imgresize($destination);
$destination2='aircraft/'.$reg."2.jpg";
$temp_file2 = $_FILES['image2']['tmp_name'];
move_uploaded_file($temp_file2,$destination2);
imgresize($destination);
$destination3='aircraft/'.$reg."3.jpg";
$temp_file3 = $_FILES['image3']['tmp_name'];
move_uploaded_file($temp_file3,$destination3);
imgresize($destination);
function imgresize($filename) {
    $source = imagecreatefromjpeg($filename);;
    $fullpath = $filename;

    list($width,  $height) = getimagesize($filename);
    $thumb = imagecreatetruecolor($newwidth,  $newheight);
imagecopyresampled($thumb,$source,0,0,0,0,200, 133,$width,$height);
    imagejpeg($thumb,  'images/thumbs/'.basename($filename),  100);
} 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.