I’m trying to display and re-size images using URL’s which are held in a Mysql database (under the column named “ImageUrl”),
the images are all from separate sources and so I need to re size them appropriately before displaying them in separate Divs, I’m still trying to get my head around a lot of PHP, so just to let you know that I’m no expert.
So far I have:
-Connected to the database
-Ran the query
-Then displayed the query result (So I can display the original image just fine by sourcing the link from the ImageUrl column, but its still massive)
So next, i suspect that I need to use the GB library to store the image after resizing it, before displaying it.
I have found find plenty of example’s online illustrating how to do this using an image which is already saved on the server, but none on how to do it using a URL sourced from a database.
And just in-case the question still seems hazy, my question is:
How do I use PHP to call upon and re-size a database URL Image?
Well you can do it that way… as long as you dont ever link to an image bigger than PHP’s memory limit.
PHP will have to load the entire image to be able to resize it.
[FPHP]file_get_contents[/FPHP] the url (if your webhost allows remote file_get_contents), [FPHP]imagecreatefromstring[/FPHP] the results, [FPHP]imagecreate[/FPHP] an image in the desired size, and then [FPHP]imagecopyresized[/FPHP] A into B. I would highly suggest then locally saving the result for quicker handling. (Note: Please make sure you have permission to copy said image from the remote site; we are not responsible for your copyright infringements!)
Thanks for both of your replies!
I attempted Lions approach but I don’t think Im experienced enough with those operators, well, not enough to put them all together anyway, although I did try
Rubbles approach seemed easier, but I still cant seem to get it to work >_<
1.I created a new file in my folder called resize.php
2.I entered this code:
<?php
$image = $_GET[“I”];
exec(“convert $image -resize 500x500 JPG:-”);
?>
And then saved it.
In my events.php file, in the specific Div i have entered this code:
<?php
$I = $attresult[‘ImageUrl’];
echo “<img src=\“resize.php?I=$I\”>”;
?>
but I’m getting no image at all, or any error codes.
Just to help keep it clear, this is my code for calling the URL from the ImageUrl Column:
<?php
$query1 = “SELECT * FROM attraction WHERE AttractionID=1”;
$attquery = mysql_query($query1) or die('query error has occured ’ . mysql_error());
$attresult = mysql_fetch_assoc($attquery);
?>
I also use this code to pull the Name and Description Column’s info.
What do you get if you go to resize.php?l=<a valid thing>? I’m gonna go ahead and guess you’re being denied access to exec, as thats a very dangerous function to give people access to on a shared host.
I have been trying to get this to work on my localhost and it would not - uploaded to my server and it does. There must be something in the setup. I see you are using a localhost as well; if it does not work I would try it on the server.
I also started with an image in the same folder as the code to get rid of any other problems; once this works add the database part etc. one bit at a time.
I assume you have Imagemagick installed and you may need to change convert to something like /usr/local/bin/convert depending on how your server is setup.