Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

could not output resize image

Status
Not open for further replies.

dldl

Programmer
May 3, 2010
40
NZ
Hi;

I got a problem to output resize image after i check the type of image.
Could anyone help me, thanks.

The test_1.php has not problem to output image, but the test_2.php could not output image.

test_1.php

Code:
<?php
$image=$_GET['image'];
// The file
$filename = '../images/thread_images/'. $image;

// Set a maximum height and width
$width = 200;
$height = 200;

// Content type
header('Content-Type: image/jpeg');


// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
imagejpeg($image_p, null, 100);


?>


test_2.php

Code:
<?php
$image=$_GET['image'];
// The file
$filename = '../images/thread_images/'. $image;

// Set a maximum height and width
$width = 200;
$height = 200;

// Content type

if(exif_imagetype($image)==IMAGETYPE_JPEG)
  header('Content-Type: image/jpeg');
else if(exif_imagetype($image)==IMAGETYPE_GIF)
  header('Content-Type:image/gif'); 


// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output


  if(exif_imagetype($imagepath)==IMAGETYPE_JPEG)
    imagejpeg($image_p, null, 100);
  else if(exif_imagetype($imagepath)==IMAGETYPE_GIF)
     imagegif($image_p, null, 100); 

?>
 
Hi

What is $imagepath's value ? Are you sure you not $filename what you intended to use ? ( Including the [tt]header()[/tt] call's [tt]if[/tt] condition too. )


Feherke.
 

you are right, i change it as following, but still not work.

Code:
if(exif_imagetype($filename)==IMAGETYPE_JPEG)
  header('Content-Type: image/jpeg');
else if(exif_imagetype($filename)==IMAGETYPE_GIF)
  header('Content-Type:image/gif'); 


  if(exif_imagetype($filename)==IMAGETYPE_JPEG)
    imagejpeg($image_p, null, 100);
  else if(exif_imagetype($filename)==IMAGETYPE_GIF)
     imagegif($image_p, null, 100);

 
In another .php file, i have a code as following, but it still could not display out the image.

Code:
$image="cat.jpg";
 echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
 
i also delete my cookie from my browser too, and restart my computer, but it still not help.
 
Hi
[ul]
[li]What happens when you type [ignore][/ignore] in the browser's location bar ?[/li]
[li]What happens when you insert [tt][navy]$_GET[/navy][teal]=[/teal]array[teal]([/teal][green]'image'[/green][teal]=>[/teal][green]'cat.jpg'[/green][teal]);[/teal][/tt] at the beginning of display_thread_image.php then execute php display_thread_image.php from the command line ?[/li]
[li]Anything appears in the web server's error log ?[/li]
[/ul]


Feherke.
 
>What happens when you type > in the browser's location bar ?

the browser tell me the webpage could not find, but my test_1.php works.

the following .php file is where i display my image file.

could you help me to check, thanks.

Code:
<?php session_start();
//include("security_check.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxxxx</title>


<script type="text/javascript" src="bbcode.js"></script>


<style type="text/css">

* {padding:0; margin:0;}

body{
  padding:0;
  border:0;
  background-color:#8F898B;
  margin:0;
}

#container {
  width:1024px;
  height:1560px;
  margin:20px auto;
  padding: 10px;
  background-color:#FFFFFF;

  border:1px solid #CCCCCC;
  

}

#top{
  width:1023px;
  height: 40px;
  background-color:#B7BEED;
  font-size:20px;
  text-align:center;
  float:left;
 
}

#top1{
  width:485px;
  height: 38px;

  float: left;
}

#top2{
  width:528px;
  height: 38px;
  float: left;

}

#nav1 {
  width: 100%;
  float: left;
  margin: 0 0 3em 0;
  padding: 0;
  list-style: none;

 }
#nav1 li {
  float: right; }
#nav1 li a {
  display: block;
  padding: 8px 15px;
  text-decoration: none;
  font-weight: bold;
  color: #069;
  border-right: 2px solid #FFFFFF; }
#nav1 li a:hover {
  color: #c00;
  background-color: #fff;
}

#leftcolumn{
  width:122px;
  height:1320px;
  border:1px solid #CCCCCC;
  float:left;

}

#midcolumn{
  width:700px;
  height:1320px;
  border:1px solid #CCCCCC;
  float:left;
}



#box{
 width:640px;
 height:1230px;
 border:1px solid #CCCCCC;
 padding-top:60px;
 padding-left:30px;
 float:left;
}

#box_note{
 width:600px;
 height:150px;
 border:1px solid #CCCCCC;
 color:#4055F5;
 font-size:16px;
 float:left;
}

#ul2{
  padding-left:15px;
}

.sbox{
 width:300px;
 height:250px;
 border:1px solid #CCCCCC;
 float:left;
 color:#4055F5;
 font-size:14px;

}


#rightcolumn{
  width:190px;
  height:1320px;
  border:1px solid #CCCCCC;
  float:left;
}

#foot{
  width:1022px;
  height:200px;
  border:1px solid #CCCCCC;
  clear:both;
}

</style>
</head>
<body>

<div id="container">

<div id="top">


<div id="top1">

</div>


<div id="top2">
<ul id="nav1">
  <li><a href="../index.php">Home</a></li>
             
</ul>
</div>


</div>


<div id="leftcolumn">

</div>

<div id="midcolumn">

<div id="box">

<div id="box_note">

Note: <br />
<ul id="ul2">
<li> You can upload 8 photos. </li>
<li>The size of image must not more than 300kb </li>
<li>The format of image must be (.jpg) or (.gif)</li>
<li><a href="[URL unfurl="true"]http://www.picresize.com/"[/URL] target="_blank"> The free website([URL unfurl="true"]http://www.picresize.com/)[/URL] to reduce the size of image and convert format</a></li>
</ul>

</div>



<?php
  include("../condatabase.php");


    global $con;



  mysql_close($con);

  function get_image_name($num){
    include("../condatabase.php");

    $thread_id=$_SESSION['upload_thread_photos_thread_id'];
    $userid=$_SESSION['login_id'];
    //echo $column_name;

    $q="select * from thread_photos where thread_id='$thread_id'";

   

    $result=mysql_query($q,$con)or die(mysql_error());

    $image_name="";
    while($row = mysql_fetch_array($result)){
       if($num==1)
         $image_name=$row['image1'];
       else if($num==2)
         $image_name=$row['image2'];   
       else if($num==3)
         $image_name=$row['image3']; 
       else if($num==4)
         $image_name=$row['image4']; 
       else if($num==5)
         $image_name=$row['image5'];   
       else if($num==6)
         $image_name=$row['image6']; 
       else if($num==7)
         $image_name=$row['image7'];     
       else if($num==8)
         $image_name=$row['image8'];   

 


    }
     return $image_name;
  }

?>




<div class="sbox">
#1
<form action="upload_thread_photos_process_3.php?a=image1" method="post"
enctype="multipart/form-data">
<div>
<label for="file11">Upload photo from your computer:</label>
<input type="file" name="file1" id="file11" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<br />


<?php

      $image=get_image_name(1);
 
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>
</div>

<div class="sbox">
#2
<form action="upload_thread_photos_process_3.php?a=image2" method="post"
enctype="multipart/form-data">
<div>
<label for="file22">Upload photo from your computer:</label>
<input type="file" name="file1" id="file22" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<br />


<?php

      $image=get_image_name(2);
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>


</div>



<div class="sbox">
#3
<form action="upload_thread_photos_process_3.php?a=image3" method="post"
enctype="multipart/form-data">
<div>
<label for="file33">Upload photo from your computer:</label>
<input type="file" name="file1" id="file33" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<?php

      $image=get_image_name(3);
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>


</div>

<div class="sbox">
#4
<form action="upload_thread_photos_process_3.php?a=image4" method="post"
enctype="multipart/form-data">
<div>
<label for="file44">Upload photo from your computer:</label>
<input type="file" name="file1" id="file44" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<?php

      $image=get_image_name(4);
 
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>


</div>

<div class="sbox">
#5
<form action="upload_thread_photos_process_3.php?a=image5" method="post"
enctype="multipart/form-data">
<div>
<label for="file55">Upload photo from your computer:</label>
<input type="file" name="file1" id="file55" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<?php

      $image=get_image_name(5);

 
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>


</div>

<div class="sbox">
#6
<form action="upload_thread_photos_process_3.php?a=image6" method="post"
enctype="multipart/form-data">
<div>
<label for="file66">Upload photo from your computer:</label>
<input type="file" name="file1" id="file66" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<?php

      $image=get_image_name(6);
 
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>


</div>

<div class="sbox">
#7
<form action="upload_thread_photos_process_3.php?a=image7" method="post"
enctype="multipart/form-data">
<div>
<label for="file77">Upload photo from your computer:</label>
<input type="file" name="file1" id="file77" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<?php

      $image=get_image_name(7);
 
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>

</div>

<div class="sbox">
#8
<form action="upload_thread_photos_process_3.php?a=image8" method="post"
enctype="multipart/form-data">
<div>
<label for="file88">Upload photo from your computer:</label>
<input type="file" name="file1" id="file88" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</div>
</form>

<?php

      $image=get_image_name(8);
 
      if(!empty($image))
         echo " <img alt=\"image\" src=\"display_thread_image.php?image=$image\"  /> ";
?>


</div>

</div>


</div>

<div id="rightcolumn">

</div>

<div id="foot">

</div>



</div>


</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top