siyah bg gösteren resim kırpma

1 Cevap php

i görüntü kırpılmış olsun ne zaman siyah bir arka plan resim eklenir bu resim kırpma kodu var. i nasıl kaldırabilirim? teşekkürler

$fldcategory = $_POST['category'];
$flname = $_FILES['upload']['name'];
$img_src = $_FILES['upload']['tmp_name'];
$thumb = "uploads/" . $flname;
$title = $_POST['title']; 

// Open image
$img = imagecreatefromjpeg($img_src);

// Store image width and height
list($img_width, $img_height) = getimagesize($img_src);

$width = '800';
$height = '600';

// Create the new image
$new_img = imagecreatetruecolor($width, $height);

// Calculate stuff and resize image accordingly
if (($width/$img_width) < ($height/$img_height)) {
    $new_width = $width;
    $new_height = ($width/$img_width) * $img_height;
    $new_x = 0;
    $new_y = ($height - $new_height) / 2;
} else {
    $new_width = ($height/$img_height) * $img_width;
    $new_height = $height;
    $new_x = ($width - $new_width) / 2;
    $new_y = 0;
} 

imagecopyresampled($new_img, $img, $new_x, $new_y, 0, 0, 
  $new_width, $new_height, $img_width, $img_height);

// Save thumbnail
if (is_writeable(dirname($thumb))) {
    imagejpeg($new_img, $thumb, 100);
} 

// Free up resources
imagedestroy($new_img);
imagedestroy($img);

1 Cevap

Bu işlevlerin göz at:

(Eğer bu rengi ayırmak gerekir) ilk fonksiyonu ile şeffaf bir renk tanımlayabilirsiniz. Bunu resized sürümünü boya önce şeffaf renk ile yeni bir resim doldurun. Bu sadece siyah bg görünmez yapacak ve doğru boyutu görüntü kırpma olmaz. (Bu size yardımcı olabilecek ne sadece bir tahmin)