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
https://forums.phpfreaks.com/topic/191658-image-manipulation/
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
https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010270
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
https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010355
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
https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010363
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
https://forums.phpfreaks.com/topic/191658-image-manipulation/#findComment-1010455
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.