I hope you can help. I have a program using 2 pages (main.php and resize_image.php) fragments shown below. Each script works fine independenly of each other. My problem comes when I want to pass a value held on my database held in $story[picture] to resize_image.php..... It simply will not transfer the data.

FACTS:
I have done a var_dump($story[picture]); in main.php and it returns exactly what I am expecting.

In main.php I have used echo "<IMG SRC=\"pictures/1.jpg\">";. This works correctly as expected.

In main.php when I substitute echo "<IMG SRC=\"pictures/1.jpg\">"; for echo "<IMG SRC=\"resize_image.php?pictures/1.jpg\">"; it does not work

When I say work this means that it displays the picture to the screen. This is the job of resize_image.php

Lastly if I put the following line at the top of resize_image.php
$image = "Club_Badge.jpg"; // dummy hard code. and the following code in main.php echo "<IMG SRC=\"resize_image.php?pictures/1.jpg\">"; I get the script to output the picture called Club_Badge.jpg which is what I expect. Therefore I know the second script (resize_image.php) is being called from main.php.

I hope this all makes sense. I have been hitting my head against a wall with this one and wonder if anyone can help

Many thanks
JPC
It's not where you end. It's where you start from

--------- CODE FOR main.php --------------------
<?php

    if (mysql_num_rows($story_result)>0)
    {
        $story = mysql_fetch_array($story_result);
        echo "<TABLE BORDER=0 WIDTH=400>";
        echo "<TR>";
        echo "<TD ROWSPAN=2 WIDTH=100>";

        if($story[picture])
        {
            $image = $story[picture];
            echo "<IMG SRC=\"resize_image.php?pictures/1.jpg\">";
// echo "<IMG SRC=\"resize_image.php?$image\">";  // ultimate goal code
        }

    }

?>


--------- CODE FOR resize_image.php -------------


<php

    if(!$max_width) $max_width = 150;       
    if(!$max_height)    $max_height = 100;      

    $size = GetImageSize($image);
    $width = $size[0];

    $height = $size[1];
    $x_ratio = $max_width/$width;
    $y_ratio = $max_height/$height;

?>

In main.php change this echo "<IMG SRC=\"resize_image.php?pictures/1.jpg\">"; to echo "<IMG SRC=\"resize_image.php?image='pictures/1.jpg'\">"; and add something to resize_image.php at the top like $image=$_GET['image']; Now I'm assuming that Club_Badge.jpg and 1.jpg are not in the same folder. That Club_Badge.jpg is in the same folder as your php scripts and 1.jpg is one folder deeper in pictures.

You could put the part to create a thumbnail inside main.php like so:

<?php

function show_thumbnail($image) {
	$path_parts = pathinfo($image);
	$basename = $path_parts['basename'];

	// width and height of thumbnail
	$new_w = 200;
	$new_h = 200;

	// get info about the image
	list($width,$height,$imgtype) = getimagesize($image);
	if (empty($imgtype)) {
		// it seems we don't have an image
		exit();
	}

	// create image depending on image type
	switch ($imgtype) {
		case 1 : $src_img=imagecreatefromgif($image);  break;
		case 2 : $src_img=imagecreatefromjpeg($image); break;
		case 3 : $src_img=imagecreatefrompng($image);  break;
	}

	// calculate thumb size keeping proportions
	$thumb_w = $new_w; $thumb_h = $new_h;
	if ($width/$height > $new_w/$new_h && $width > $new_w) {
		$thumb_w = $new_w;
		$thumb_h = $new_w/$width * $height;
	}
	else if ($height > $new_h) {
		$thumb_w = $new_h/$height * $width;
		$thumb_h = $new_h;
	}

	// Create new image for thumb
	$dst_img = imagecreatetruecolor($thumb_w,$thumb_h); 
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$width,$height);

	// Save the thumbnail (in the folder thumbs)
	imagejpeg($dst_img,"thumbs/".$basename);
	
	 // And display it
	 echo "<img src=\"thumbs/".$basename."\">";
}

// Your code to open and query the database

if (mysql_num_rows($story_result)>0) {
	$story = mysql_fetch_array($story_result);
	echo "<TABLE BORDER=0 WIDTH=400>";
	echo "<TR>";
	echo "<TD ROWSPAN=2 WIDTH=100>";

	if($story[picture]) {
		$image = $story[picture];
		show_thumbnail($image);
	}
}

// Rest of your code

?>

The above code will check for a gif, jpeg or png image, create a thumbnail (type jpeg) in the folder thumbs and display it like a normal image.

You could put the part to create a thumbnail inside main.php like so:

<?php

function show_thumbnail($image) {
	$path_parts = pathinfo($image);
	$basename = $path_parts['basename'];

	// width and height of thumbnail
	$new_w = 200;
	$new_h = 200;

	// get info about the image
	list($width,$height,$imgtype) = getimagesize($image);
	if (empty($imgtype)) {
		// it seems we don't have an image
		exit();
	}

	// create image depending on image type
	switch ($imgtype) {
		case 1 : $src_img=imagecreatefromgif($image);  break;
		case 2 : $src_img=imagecreatefromjpeg($image); break;
		case 3 : $src_img=imagecreatefrompng($image);  break;
	}

	// calculate thumb size keeping proportions
	$thumb_w = $new_w; $thumb_h = $new_h;
	if ($width/$height > $new_w/$new_h && $width > $new_w) {
		$thumb_w = $new_w;
		$thumb_h = $new_w/$width * $height;
	}
	else if ($height > $new_h) {
		$thumb_w = $new_h/$height * $width;
		$thumb_h = $new_h;
	}

	// Create new image for thumb
	$dst_img = imagecreatetruecolor($thumb_w,$thumb_h); 
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$width,$height);

	// Save the thumbnail (in the folder thumbs)
	imagejpeg($dst_img,"thumbs/".$basename);
	
	 // And display it
	 echo "<img src=\"thumbs/".$basename."\">";
}

// Your code to open and query the database

if (mysql_num_rows($story_result)>0) {
	$story = mysql_fetch_array($story_result);
	echo "<TABLE BORDER=0 WIDTH=400>";
	echo "<TR>";
	echo "<TD ROWSPAN=2 WIDTH=100>";

	if($story[picture]) {
		$image = $story[picture];
		show_thumbnail($image);
	}
}

// Rest of your code

?>

The above code will check for a gif, jpeg or png image, create a thumbnail (type jpeg) in the folder thumbs and display it like a normal image.

Thanks for the reply. I wanted a more modular approach but see where you're going. Thanks for your time and effort though

Regards JPC

In main.php change this
echo "<IMG SRC=\"resize_image.php?pictures/1.jpg\">";

to
echo "<IMG SRC=\"resize_image.php?image='pictures/1.jpg'\">";

and add something to resize_image.php at the top like
$image=$_GET['image'];

Now I'm assuming that Club_Badge.jpg and 1.jpg are not in the same folder. That Club_Badge.jpg is in the same folder as your php scripts and 1.jpg is one folder deeper in pictures.

Thanks for that. I've put the code here so others can see the results. I pick the picture from my database field

resize_image.php now gets the picture that I want and everything works... thanks so much for your help

Regards JPC

main.php

if (mysql_num_rows($story_result)>0)
{
   $story = mysql_fetch_array($story_result);
   echo "<TABLE BORDER=0 WIDTH=400>";
   echo "<TR>";
   echo "<TD ROWSPAN=2 WIDTH=100>";

   if($story[picture])
   {
      echo "<IMG SRC=\"resize_image.php?image=$story[picture]\">";
   }

   rest of code ... .....

resize_image.php

<?php

//$image = "Club_Badge.jpg";   // dummy hard code.
$image = $_GET['image'];

if(!$max_width)   $max_width = 150;     //was 150
if(!$max_height)  $max_height = 100;        //was  100

$size = GetImageSize($image);
$width = $size[0];

$height = $size[1];

     rest of code ... .....
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.