Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this basic imagejpeg() resizer returns a black image?
    primarykey
    data
    text
    <p><em>EDIT</em></p> <p>Thanks for all your answers, especially @Mailerdaimon who noticed that I wasn't using the computed values in the <code>imagecopyresampled</code> function.</p> <p>I don't get black images anymore, but i still do get some black part so i figure my ratio formula should be updated : if i upload a landscape image, the height of the new image is smaller than 170px, and then there's some black showing. </p> <p><strong>How can i make sure the height of the image goes all the way ?</strong></p> <hr> <p>Below is a <strong>simple script to allow users upload pictures</strong>. Once the upload is done, the pictures are displayed as a 170px(h) x 150px(w) thumbnail.</p> <p><strong>The resize part does work</strong> since the output image is 170x150px BUT i still get some black area if</p> <pre><code>if ($_SERVER["REQUEST_METHOD"] == "POST") { $maxWidth = 150; $maxHeight = 170; $name = $_FILES ['image'] ['name']; $type = $_FILES ["image"] ["type"]; $size = $_FILES ["image"] ["size"]; $tmp_name = $_FILES ['image'] ['tmp_name']; list($originalWidth, $originalHeight) = getimagesize($tmp_name); if ($originalWidth &gt; $originalHeight) { $thumbnail_height = floor(($originalHeight/$originalWidth)*$maxWidth); $thumbnail_width = $maxWidth; } else { $thumbnail_width = floor(($originalWidth/$originalHeight)*$maxHeight); $thumbnail_height = $maxHeight; } // Resample $image_p = imagecreatetruecolor($maxWidth, $maxHeight); imagecreatefrompng($tmp_name); imagecopyresampled($image_p, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $originalWidth, $originalHeight); //start upload process $RandomNumber = uniqid(); $location = "uploads/$RandomNumber"; imagejpeg($image_p, $location, 100); $sql=query("UPDATE users SET image = '".$location."' WHERE id = '$id'"); } } </code></pre> <p>Any idea what I'm doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload