Jump to content

Image Resize returning a black image?


cooldude832

Recommended Posts

I made this

<?php
$img_types = array("image/jpg", "image/pjpg", "image/jpeg", "iamge/pjpeg");
$new_path = ROOT."graphics/facilitators/".$_SESSION['FacID'].".jpg";
if (in_array($_FILES['image']['type'], $img_types)){ 
if(copy ($_FILES['image']['tmp_name'], $new_path)){
	$target = 150;
	if ($width > $height) {
		$percentage = ($target / $width);
	}
	else {
		$percentage = ($target / $height);
	}
	//gets the new value and applies the percentage, then rounds the value
	$width = round($width * $percentage);
	$height = round($height * $percentage); 
	$imgdata = getimagesize($new_path);
	$thumb = ImageCreateTrueColor(150, 150);
    list($width, $height) = getimagesize($new_path);
    imagecopyresized($thumb, $new_path, 0, 0, 0, 0, 150, 150, $width, $height);
	imagejpeg($thumb,$new_path);
?>

which uploads and moves 100% fine if I don't resize, but as soon as I added the resize It just outputs a black 150x150 as the image.

Any ideas??

Link to comment
https://forums.phpfreaks.com/topic/73161-image-resize-returning-a-black-image/
Share on other sites

solved it forgot I needed to use the img data and not the actual file source

this is the whole thing if anyone wants it

<?php
$img_types = array("image/jpg", "image/pjpg", "image/jpeg", "iamge/pjpeg");
$new_path = ROOT."graphics/facilitators/".$_SESSION['FacID'].".jpg";
if (in_array($_FILES['image']['type'], $img_types)){ 
if(copy ($_FILES['image']['tmp_name'], $new_path)){
	$target = 150;
	if ($width > $height) {
		$percentage = ($target / $width);
	}
	else {
		$percentage = ($target / $height);
	}
	//gets the new value and applies the percentage, then rounds the value
	$width = round($width * $percentage);
	$height = round($height * $percentage); 
	$imgdata = getimagesize($new_path);
	$thumb = ImageCreateTrueColor(150, 150);
    list($width, $height) = getimagesize($new_path);
	$source = imagecreatefromjpeg($new_path);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, 150, 150, $width, $height);
	imagejpeg($thumb,$new_path,100);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.