PHP原比例生成縮略圖

phpfg 9年前發布 | 1K 次閱讀 PHP

<?php
$image = "jiequ.jpg"; // 原圖
$imgstream = file_get_contents($image);
$im = imagecreatefromstring($imgstream);
$x = imagesx($im);//獲取圖片的寬
$y = imagesy($im);//獲取圖片的高

// 縮略后的大小 $xx = 140; $yy = 200;

if($x>$y){ //圖片寬大于高 $sx = abs(($y-$x)/2); $sy = 0; $thumbw = $y; $thumbh = $y; } else { //圖片高大于等于寬 $sy = abs(($x-$y)/2.5); $sx = 0; $thumbw = $x; $thumbh = $x; } if(function_exists("imagecreatetruecolor")) { $dim = imagecreatetruecolor($yy, $xx); // 創建目標圖gd2 } else { $dim = imagecreate($yy, $xx); // 創建目標圖gd1 } imageCopyreSampled ($dim,$im,0,0,$sx,$sy,$yy,$xx,$thumbw,$thumbh); header ("Content-type: image/jpeg"); imagejpeg ($dim, false, 100); ?></pre>

 本文由用戶 phpfg 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!