Hi all,

I'm very new to php and I'm working on a project that require to create compcard that should be saved in a folder (uploade) which is working properly.
The problem is that now I have to preview that copcard (images) and ask user to save it or not. can anyone know. Plz help me.

my email is <email snipped>
Thank you

<?php 
// The file you are resizing 
$file = $_GET['filename'];

$sizeset = false;
list($width, $height) = getimagesize($file); 

//This will set our output size depending on input

if($_GET['pct']) {               // First type - percentage of original size
	$size = $_GET['pct']/100; 
	$modwidth = $width * $size; 
	$modheight = $height * $size; 
	$sizeset = true;
} 

if($_GET['maxw']) {               // Second type - Determine Max Width of thumbnails
	$wpct = $_GET['maxw'] / $width;
	$modwidth = $_GET['maxw'];
	$modheight = round($height*$wpct);
	$sizeset = true;
} 

if($_GET['maxh']) {               // Third type - Determine Max Height of thumbnails
	$hpct = $_GET['maxh'] / $height;
	$modheight = $_GET['maxh'];
	$modwidth = round($width*$hpct);
	$sizeset = true;
} 

if(!$sizeset) {	               // Fourth type - If nothing else specified, default to this percentage
	$size = .25;					// This is set for 25%
	$modwidth = $width * $size; 
	$modheight = $height * $size; 
} 

// This sets it to a .jpg, but you can change this to png or gif 
header('Content-type: image/jpeg'); 

// Resizing the Image 
$tn = imagecreatetruecolor($modwidth, $modheight); 
$image = imagecreatefromjpeg($file); 
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); 

// Outputting a .jpg, you can make this gif or png if you want 
//notice we set the quality (third value) to 100 
imagejpeg($tn, null, 100); 
?>

So, when you need the thumbnail, you can call it like these examples, depending on what you need:

<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&pct=30">
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&maxw=150">
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&maxh=100">
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg">
commented: hey thanx Wraithmanilian +0

hey thanx Wraithmanilian

I'll try this. thanx a lot.

<?php 
// The file you are resizing 
$file = $_GET['filename'];

$sizeset = false;
list($width, $height) = getimagesize($file); 

//This will set our output size depending on input

if($_GET['pct']) {               // First type - percentage of original size
	$size = $_GET['pct']/100; 
	$modwidth = $width * $size; 
	$modheight = $height * $size; 
	$sizeset = true;
} 

if($_GET['maxw']) {               // Second type - Determine Max Width of thumbnails
	$wpct = $_GET['maxw'] / $width;
	$modwidth = $_GET['maxw'];
	$modheight = round($height*$wpct);
	$sizeset = true;
} 

if($_GET['maxh']) {               // Third type - Determine Max Height of thumbnails
	$hpct = $_GET['maxh'] / $height;
	$modheight = $_GET['maxh'];
	$modwidth = round($width*$hpct);
	$sizeset = true;
} 

if(!$sizeset) {	               // Fourth type - If nothing else specified, default to this percentage
	$size = .25;					// This is set for 25%
	$modwidth = $width * $size; 
	$modheight = $height * $size; 
} 

// This sets it to a .jpg, but you can change this to png or gif 
header('Content-type: image/jpeg'); 

// Resizing the Image 
$tn = imagecreatetruecolor($modwidth, $modheight); 
$image = imagecreatefromjpeg($file); 
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); 

// Outputting a .jpg, you can make this gif or png if you want 
//notice we set the quality (third value) to 100 
imagejpeg($tn, null, 100); 
?>

So, when you need the thumbnail, you can call it like these examples, depending on what you need:

<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&pct=30">
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&maxw=150">
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&maxh=100">
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg">

If this solves the problem, please mark it solved. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.