Я пытаюсь обрезать и изменять размер изображений. Когда изображения перемещаются в папку resized_images, все изображения становятся черными, но изображения изменяются (535 * 313). Вот мой код, который я пробовал до сих пор. Не могли бы вы предложить мне правильный способ сделать это? поблагодарить уОбрезать и изменить размер изображений в php
<form action="" method="POST" enctype="multipart/form-data">
<input id="input-6" name="slideshow_images[]" type="file" multiple class="file-loading">
<input type="submit" name="sub" >
</form>
<?php
if(isset($_POST['sub']))
{
$pic = $_FILES["slideshow_images"]["name"]; \t
foreach($pic as $pic_src)
{ \t
$image = imagecreatefromjpeg($pic_src);
$filename = 'resized_images/'.$pic_src.'cropped_whatever.jpeg';
$thumb_width = 535;
$thumb_height = 313;
$width = imagesx($image);
$height = imagesy($image);
\t
$original_aspect = $width/$height;
$thumb_aspect = $thumb_width/$thumb_height;
if ($original_aspect >= $thumb_aspect)
{
// If image is wider than thumbnail (in aspect ratio sense)
$new_height = $thumb_height;
$new_width = $width/($height/$thumb_height);
}
else
{
// If the thumbnail is wider than the image
$new_width = $thumb_width;
\t
$new_height = $height/($width/$thumb_width);
}
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
// Resize and crop
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width)/2, // Center the image horizontally
0 - ($new_height - $thumb_height)/2, // Center the image vertically
0, 0,
$new_width, $new_height,
$width, $height);
imagejpeg($thumb, $filename, 80);
}
}
?>
Где следует Я выделяю true color.please ответ – silent
Прежде чем вы выполните imagecopyresample и imagefill или imagefilledrectangle. В противном случае это не очень хорошо. :-) Модифицированный ответ. –
Я не хочу, чтобы заполнить новый цвет, просто я хочу отображать те же изображения, что я загрузил. Возможно ли это? – silent