Jump to content

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

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.