私はあなたの問題を教えてくれるので、私はPHPのコードを作っています。良いことは、画像を作ってくれます。$ thumb_widthと$ thumb_heightは同じ値ですが、この場合、私はこの解像度(200 * 150)の画像を望んでいません ここにコードがあり、間違いを見つけることができません。この例では作物の画像PHPの変形、ワープされた
<?php
function create_thumb($directory, $image, $destination) {
$image_file = $image;
$image = $directory.$image;
if (file_exists($image)) {
$source_size = getimagesize($image);
if ($source_size !== false) {
$thumb_width = 200;
$thumb_height = 150;
switch($source_size['mime']) {
case 'image/jpeg':
$source = imagecreatefromjpeg($image);
break;
case 'image/png':
$source = imagecreatefrompng($image);
break;
case 'image/gif':
$source = imagecreatefromgif($image);
break;
}
$source_aspect = round(($source_size[0]/$source_size[1]), 1);
$thumb_aspect = round(($thumb_width/$thumb_height), 1);
if ($source_aspect < $thumb_aspect) {
$new_size = array($thumb_width, ($thumb_width/$source_size[0]) * $source_size[1]);
$source_pos = array(0, ($new_size[1] - $thumb_height)/2);
} else if ($source_aspect > $thumb_aspect) {
$new_size = array(($thumb_width/$source_size[1]) * $source_size[0], $thumb_height);
$source_pos = array(($new_size[0] - $thumb_width)/2, 0);
} else {
$new_size = array($thumb_width, $thumb_height);
$source_pos = array(0, 0);
}
if ($new_size[0] < 1) $new_size[0] = 1;
if ($new_size[1] < 1) $new_size[1] = 1;
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $source, 0, 0, $source_pos[0], $source_pos[1], $new_size[0], $new_size[1], $source_size[0], $source_size[1]);
switch($source_size['mime']) {
case 'image/jpeg':
imagejpeg($thumb, $destination.$image_file);
break;
case 'image/png':
imagepng($thumb, $destination.$image_file);
break;
case 'image/gif':
imagegif($thumb, $destination.$image_file);
break;
}
}
}
}
?>
私は「)=私の英語のため申し訳ありません」ラップ(533px * 300ピクセル)、それが変形していますの画像を、置けば、私はこれで助けを必要としてください。あなたが解決策を見つけたら、私は本当にplesedされるでしょう。
ありがとう、マティアス。
空白はありますか? –