note 100486 added to function.imagecreatefromjpeg

From: Date: Tue, 19 Oct 2010 09:58:02 +0000
Subject: note 100486 added to function.imagecreatefromjpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-173269@lists.php.net to get a copy of this message
There is my actual script to resize image without distortion to generate a thumbnail and/or show a smaller to browser. <?php // usual header used on my all pages ob_start("ob_gzhandler"); $PHP_SELF=$_SERVER['PHP_SELF']; include "include/errors.php"; //error log script // actual script begins here $type=false; function open_image ($file) { //detect type and process accordinally global $type; $size=getimagesize($file); switch($size["mime"]){ case "image/jpeg": $im = imagecreatefromjpeg($file); //jpeg file break; case "image/gif": $im = imagecreatefromgif($file); //gif file break; case "image/png": $im = imagecreatefrompng($file); //png file break; default: $im=false; break; } return $im; } $url = $_GET['url']; if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($url))) { // send the last mod time of the file back header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($url)).' GMT', true, 304); //is it cached? } else { $image = open_image($url); if ($image === false) { die ('Unable to open image'); } $w = imagesx($image); $h = imagesy($image); //calculate new image dimensions (preserve aspect) if(isset($_GET['w']) && !isset($_GET['h'])){ $new_w=$_GET['w']; $new_h=$new_w * ($h/$w); } elseif (isset($_GET['h']) && !isset($_GET['w'])) { $new_h=$_GET['h']; $new_w=$new_h * ($w/$h); } else { $new_w=isset($_GET['w'])?$_GET['w']:560; $new_h=isset($_GET['h'])?$_GET['h']:560; if(($w/$h) > ($new_w/$new_h)){ $new_h=$new_w*($h/$w); } else { $new_w=$new_h*($w/$h); } } $im2 = ImageCreateTrueColor($new_w, $new_h); imagecopyResampled ($im2, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h); //effects if(isset($_GET['blur'])){ $lv=$_GET['blur']; for($i=0; $i<$lv;$i++){ $matrix=array(array(1,1,1),array(1,1,1),array(1,1,1)); $divisor = 9; $offset = 0; imageconvolution($im2, $matrix, $divisor, $offset); } } if(isset($_GET['sharpen'])){ $lv=$_GET['sharpen']; for($i=0; $i<$lv;$i++){ $matrix = array(array(-1,-1,-1),array(-1,16,-1),array(-1,-1,-1)); $divisor = 8; $offset = 0; imageconvolution($im2, $matrix, $divisor, $offset); } } header('Content-type: image/jpeg'); $name=explode(".", basename($_GET['url'])); header("Content-Disposition: inline; filename=".$name[0]."_t.jpg"); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($url)) . ' GMT'); header("Cache-Control: public"); header("Pragma: public"); imagejpeg($im2); //imagedestroy($im2); //imagedestroy($image); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 78.62.119.114 ---- Manual Page -- http://www.php.net/manual/en/function.imagecreatefromjpeg.php Edit -- https://master.php.net/note/edit/100486 Del: integrated -- https://master.php.net/note/delete/100486/integrated Del: useless -- https://master.php.net/note/delete/100486/useless Del: bad code -- https://master.php.net/note/delete/100486/bad+code Del: spam -- https://master.php.net/note/delete/100486/spam Del: non-english -- https://master.php.net/note/delete/100486/non-english Del: in docs -- https://master.php.net/note/delete/100486/in+docs Del: other reasons-- https://master.php.net/note/delete/100486 Reject -- https://master.php.net/note/reject/100486 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173269) next »