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
https://forums.phpfreaks.com/topic/75267-solved-image-resize-problem/
Share on other sites

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.