Jump to content

Auto Thumbnails


QWERTYtech

Recommended Posts

I think i have the script for you, 1 sec...

 

<?php

$file = $_GET['source'];
list($width,$height)=getimagesize($file);
$type = exif_imagetype($file);

//Types
/*
1  	IMAGETYPE_GIF
2 	IMAGETYPE_JPEG
3 	IMAGETYPE_PNG
4 	IMAGETYPE_SWF
5 	IMAGETYPE_PSD
6 	IMAGETYPE_BMP
7 	IMAGETYPE_TIFF_II (intel byte order)
8 	IMAGETYPE_TIFF_MM (motorola byte order)
9 	IMAGETYPE_JPC
10 	IMAGETYPE_JP2
11 	IMAGETYPE_JPX
12 	IMAGETYPE_JB2
13 	IMAGETYPE_SWC
14 	IMAGETYPE_IFF
15 	IMAGETYPE_WBMP
16 	IMAGETYPE_XBM
*/
if($type == 2){
$src = imagecreatefromjpeg($file);
}elseif($type == 3){
$src = imagecreatefrompng($file);
}elseif($type == 1){
$src = imagecreatefromgif($file);
}else{
die("Unsupported file type (".$type.")");
}

if($width > $height){
$newwidth=200;
$newheight=($height/$width)*$newwidth;
}else{
$newheight=200;
$newwidth=($width/$height)*$newheight;
}

$tmp=imagecreatetruecolor($newwidth,$newheight);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

header("Content-type: image/jpeg");
imagejpeg($tmp, NULL,100);

imagedestroy($src);
imagedestroy($tmp);

?>

Link to comment
https://forums.phpfreaks.com/topic/136683-auto-thumbnails/#findComment-715934
Share on other sites

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.