Jump to content

image manipulation


saunders1989

Recommended Posts

im just trying to use the script i have to shrink down some images that are massive but for some reason i cant get it to work. when i click on a thumbnail which i use the script to create it redirects you to a page called image.php and that displays the image in its full size but i need to shrink it down a little.

 

so far on my image.php file my code looks like this:

 

<?php
$dbLink = new mysqli('localhost', 'root', '', 'gallery');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}

if(isset($_GET['id']) && is_numeric($_GET['id'])) {
/* $_GET['id'] passes our test, so perform security functions on it & assign it to the $id variable */
$id= $dbLink->real_escape_string($_GET['id']);
} else {
/* it doesn't exist or it isn't numeric so assign a default value so our query below always gets constructed properly & safely */
$id = 1;
}


/* construct the query */
$query = "SELECT name, size, image_path FROM images WHERE id = $id";

/* run the query */
$result = $dbLink->query($query);

$maxheight=300;

$maxwidth=250;
$row = $result->fetch_row();
list($width, $height) = getimagesize($row[2]);
if ($width > $maxwidth || $height > $maxheight) {
  		echo "<img src=\"imageResize.php?imageFilename=" . $row[2] . "&maxHeight=" . $maxheight . "&maxWidth=" . $maxwidth . "\" />\n";
	} 
else {
  			echo "<img src=\"" . $row[2] . "\" />";
	} 

?>

 

only problem is i get an error :

 

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in C:\wamp\www\Blean_Photos\image.php on line 70

 

and i dont understand how to fix it.

 

if you need more explanation im glad to explain

 

Thanks

Link to comment
Share on other sites

The first thing to do is find out what you are getting in $row by doing print_r($row);

 

then you can find out why it is not as expected.

 

for debug, you might also like to check your query worked by doing

$result = $dbLink->query($query) or die(mysql_error().'  '.$query);

Link to comment
Share on other sites

I am not sure but maybe u get $row with named keys?

so for example u shoud try use $row['image_path'] instead $row[2]

 

and btw where u put print_r as jl5501  sugessted?

u should put it after $row = $result->fetch_row();

 

$row = $result->fetch_row();

print_r($row);

Link to comment
Share on other sites

if the class function fetch_row is akin to mysql_fetch_row, then it is being processed correctly.

 

furthermore print_r is printing nothing suggesting that it is getting nothing

 

There is probably a function akin to mysql_num_rows() that he can call which would further check

Link to comment
Share on other sites

i dont understand why when i put print_r($row) i still only shows that error message. which is really odd.

 

here is how i use my imageResize script to create my thumbnails.

 

while ($row = $result->fetch_assoc()) {

echo "<a href=\"image.php?id=" . $row['id'] . "\">";
echo "<img src=\"imageResize.php?imageFilename=" . $row['name'] . "&maxHeight=120,&maxWidth=150\" />\n";
echo "</a>\n";

 

all i want to do is use that similiar method to just shrink down the large images to a easier size to view.

Link to comment
Share on other sites

this is what i get when i echo the query:

 

SELECT name, size, image_path FROM images WHERE id = 53

 

the 53 is cause ive had loads of images in my database and my incrementing number has risen up and starts at that number.

 

is there not a way of changing this bitof code:

 

while ($row = $result->fetch_assoc()) {

echo "<a href=\"image.php?id=" . $row['id'] . "\">";
echo "<img src=\"imageResize.php?imageFilename=" . $row['name'] . "&maxHeight=120,&maxWidth=150\" />\n";
echo "</a>\n";

}

 

so i can incoprate that into the image.php file which has only this at the moment:

 

while($row = $result->fetch_row()) {
echo "<img src=\"" . $row[2] . "\" />"; // you could also play with the other $row[] variables returned by the query here.
}

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.