/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$upfile = $_REQUEST['p']; $max_width = $_REQUEST["w"]; $max_height = $_REQUEST["h"]; $def_width = $_REQUEST["wh"]; $def_height = $_REQUEST["hw"]; $def_width = '245'; $def_height = '245'; } if ($def_height=='') $def_height = $def_width; //IMAGE PATH $exportPng = false; if(!file_exists($_SERVER['DOCUMENT_ROOT'] . $upfile)) $upfile = $_SERVER['DOCUMENT_ROOT'] . $upfile; else { $upfile = "img/nophoto.jpg"; $exportPng = true; } //since we already have predefined values of extension //INCREASE MEMORY LIMIT WHEN WORKING WITH //MAKE NEW IMAGE OUT OF EXTENSION $width = $size[0]; $height = $size[1]; if ($def_width == '') { // Proportionally resize the image to the max sizes if (($max_width == '')&&($max_height == '')) { $max_width = $width; $max_height = $height; } if ($max_width == '') $max_width = ($max_height*$width) / $height; if ($max_height == '') $max_height = ($max_width*$height) / $width; if ($max_height > $max_width) $highter_dimension=$max_height; else $highter_dimension = $max_width; if ($width == 0) $x_ratio = $max_width; else $x_ratio = $max_width / $width; if ($height == 0) $y_ratio = $max_height; else $y_ratio = $max_height / $height; if( ($width <= $max_width) && ($height <= $max_height) ) { $tn_width = $width; $tn_height = $height; } elseif (($x_ratio * $height) < $max_height) { $tn_width = $max_width; } else { $tn_height = $max_height; } } if($def_width != '') { $highter_dimension = $def_width; if ($def_width < $def_height) $highter_dimension = $def_height; $factor_w = $width / $def_width; $factor_h = $height / $def_height; if ($factor_w > $factor_h) { } else { } @ImageCopyResized($dst, $src, 0, 0, $src_x, $src_y, $def_width, $def_height, $new_width, $new_height); } //OUTPUT INTO PNG TO GET HIGHER QUALITY IMAGE
URL: http://stuntsnippets.com/php-thumbnail-generator/