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
https://forums.phpfreaks.com/topic/217430-creating-a-basic-thumbnail/
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; 
} 
?>

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);
} 
?>

Archived

This topic is now archived and is closed to further replies.

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