Jump to content

[SOLVED] Image resize problem...


miligraf

Recommended Posts

Hello, what i am trying to do is to upload an image and check if it exceeds a width of 550 pixels, if it does then it should resize it but i get these two warnings:

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/content/m/i/l/miligraf/html/jaimev/pag/imagen_test.php on line 30

 

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/m/i/l/miligraf/html/jaimev/pag/imagen_test.php on line 33

 

Here is the code:

 

<?
if($_POST['ponerfotos']){
$cuan = $_POST['cuan'];
for ($i=1; $i<=$cuan; $i++){
	$cantfoto=$_POST['cantfoto'];
	for ($j=1; $j<=$cantfoto; $j++){
		$file_name = $HTTP_POST_FILES['imagen_'.$i.'_'.$j]['name'];
		$valid = array (".jpg",".jpeg");
		$random_digit=rand(00000,99999);
		$new_file_name=$random_digit.$file_name;
		$path= "/home/content/m/i/l/miligraf/html/jaimev/img_anuncios/".$new_file_name;
		$img= "http://www.miligraf.com/jaimev/img_anuncios/".$new_file_name;

		if(copy($HTTP_POST_FILES['imagen_'.$i.'_'.$j]['tmp_name'], $path)){
			$type = strtolower(strstr($file_name, '.'));
			if (!in_array($type, $valid)){
				echo 'La imágen #'.$j.' del anuncio #'.$i.'no es un archivo .JPG ó .JPEG, porfavor vuelva a subir dicha imágen.';
				unlink($path);
			}else{
				list($width, $height)=getimagesize($path);
				if ($width>550){
					$new_img = imagecreatefromjpeg($tmp_name);
					$diferencia=$width-550;
					$nuevowidth=550;
					$nuevoheight=$height-$diferencia;
					if (function_exists(imagecreatetruecolor)){
						$resized_img = imagecreatetruecolor($nuevowidth,$nuevoheight);
					}else{
						die("Error: Please make sure you have GD library ver 2+");
					}
					imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $nuevowidth, $nuevoheight, $width, $height);
					imagejpeg($resized_img,$path);
					imagedestroy($resized_img);
					imagedestroy($new_img);
				}
				echo $resized_img; ?>
				<img src="<? echo $resized_img; ?>" >
<?
			}
		}
	}
}
}else{ ?>
<div class="pasos"><span>Paso 1</span> > <span>Paso 2</span> > Paso 3<br/>
Subir imágenes de anuncio(s).</div>							
<br/>
<? 	include('../conbd.php');
$query="SELECT cantfoto FROM stats WHERE ip='miligraf'";
extract($row = mysql_fetch_array(mysql_query($query))) or die ("Error: $query. " . mysql_error()); ?>
Tu cuenta solo te permite subir <? echo $cantfoto; ?> fotos por anuncio y las imágenes deben ser .jpg ó .jpeg
<br/><br/>
<div align="left">
<form action="" method="post" enctype="multipart/form-data">
<?	$cuan = 1;
for ($i=1; $i<=$cuan; $i++){ ?>
	<div class="mayuscula"><strong>Anuncio #<? echo $i; ?></strong></div><br/>
	<? for ($j=1; $j<=$cantfoto; $j++){ ?>
		Imágen #<? echo $j; ?>
		<input name="imagen_<? echo $i;?>_<? echo $j; ?>" type="file" class="campo" size="85%"><br/>
	<? }?>
	<br/>
<? 	} ?>
<input type="hidden" name="cuan" value="<? echo $cuan; ?>">
<input type="hidden" name="cantfoto" value="<? echo $cantfoto; ?>">
<input name="ponerfotos" type="Submit" class="campo" value="Agregar"> <input type="reset" class="campo" value="Limpiar"></form>
</div>
<? } ?>

 

Thanks for your help!

Link to comment
Share on other sites

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.