我使用jQuery的imgAreaSelect插件來裁剪圖像並保存縮略圖以便在例如比例發生變化的情況下使用。令人遺憾的是,結果與我所期望的並不相符,而我無法做到。圖像被整體調整大小而不是被裁剪。PHP GD作物和比例尺圖像
這裏的測試例子:
<?php
/***
*
* $_GET returned values
*
* x1 = 0
* x2 = 400
* y1 = 66
* y2 = 258
* w = 400
* h = 192
* folder = widethumb
* filename = IMG_4591.jpg
* scale = 48
*
* Original image properties
*
* width = 600px
* height = 900px
*
***/
define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
extract($_GET);
$fn = $filename;
$filename = DOCROOT.$filename;
list($width, $height) = getimagesize($filename);
$src = imagecreatefromjpeg($filename);
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, 0, 0, (int) $x1, (int) $y1, (int) $w, (int) $h, $width, $height);
header('Content-Type: image/jpeg');
imagejpeg($dst);
什麼我mising這裏?
乾杯!
沒有工作,顯示的圖像似乎指向'0,0',而不是'0,66'。 – yoda
你可以發佈你的更新代碼。由於它對我來說非常合適,請參閱更新我的答案。 – danishgoel
解決了這個問題,在'imagecopyresampled'上使用'$ width'和'$ height',我會堅持下去,在需要按比例顯示時在'img'標籤上定義'width'和'height'。不是最好的解決方案,但它也可以。我忘記的另一件事是我用小規模('2/3'或原來的)'jQuery'顯示圖像,因此給我一個奇怪的結果。謝謝,你的答案幫助:) – yoda