Jump to content

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);
?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.