[PHP] Re: outputing image part 2
Thanks Stut we are getting somewhere. Removing the header gives the full binary output of the file in IE and FF. I also removes the echos and have the resized image showing in the browser. So far so good. I know it works. Now back to sending the URL. I have this $img_url=http://www.xxx.co.uk/images/ENbb24469/room1.JPG;; echo img src=\common/display_image.php?img_url='$img_url'\ width=\200\ height=\100\ /; and on the display image page I have: $img_url= $_GET['img_url']; $image = imagecreatefromjpeg($img_url); if ($image === false) { exit; } /// rest of the resize code goes here. This still does not work but if I plug the url in manually at the top of display_image.php it works, this suggests it is not being sent properly. Many thanks, R. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: outputing image part 2
Hi Ross, Friday, June 15, 2007, 10:00:53 PM, you wrote: I have this $img_url=http://www.xxx.co.uk/images/ENbb24469/room1.JPG;; echo img src=\common/display_image.php?img_url='$img_url'\ width=\200\ height=\100\ /; and on the display image page I have: $img_url= $_GET['img_url']; $image = imagecreatefromjpeg($img_url); if ($image === false) { exit; } /// rest of the resize code goes here. This still does not work but if I plug the url in manually at the top of display_image.php it works, this suggests it is not being sent properly. You are sending a complete URL to your image, not a path. This means that if your installation of PHP does NOT have the ability to open files from URLs (allow_url_fopen) then it won't be able to open the image from the location you gave it. If you want to load in images from other web sites then make sure allow_url_fopen is enabled in PHP. If you don't want to do this, then don't pass in a URL, pass in the *path* to the image instead. Cheers, Rich -- Zend Certified Engineer http://www.corephp.co.uk Never trust a computer you can't throw out of a window -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: outputing image part 2
Ross wrote: Thanks Stut we are getting somewhere. Removing the header gives the full binary output of the file in IE and FF. I also removes the echos and have the resized image showing in the browser. So far so good. I know it works. Now back to sending the URL. I have this $img_url=http://www.xxx.co.uk/images/ENbb24469/room1.JPG;; echo img src=\common/display_image.php?img_url='$img_url'\ width=\200\ height=\100\ /; and on the display image page I have: $img_url= $_GET['img_url']; $image = imagecreatefromjpeg($img_url); if ($image === false) { exit; } /// rest of the resize code goes here. This still does not work but if I plug the url in manually at the top of display_image.php it works, this suggests it is not being sent properly. OK, your problem here is the single quotes in the img src around $img_url. However, I question what you are actually doing. Is the image on the same machine as this script? If so you should be using a filename not the URL. Also, are you sure you're really saving anything by resizing the image on your server like this? You should consider generating the smaller version using a cron job and linking to it directly. Resizing images on the fly is one of the quickest ways to destroy the scalability of a website. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: outputing image part 2
On 6/15/07, Stut [EMAIL PROTECTED] wrote: OK, your problem here is the single quotes in the img src around $img_url. Stut's right. You should change: echo img src=\common/display_image.php?img_url='$img_url'\ width=\200\ height=\100\ /; to: echo img src=\common/display_image.php?img_url=.$img_url.\ width=\200\ height=\100\ /; He's also right about the dynamic resizing of images causing a serious strain on the server. Each time it has to do that, it uses up a significant amount of resources for a seemingly quick and small operation. Multiply that by n number of simultaneous accesses and you can see the exponential - and potentially devastating - pitfallic results. -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: outputing image part 2
I am taking your advice. I am going to rezize any image greater than 400px wide prior to upload. I have to combine my upload script for ($i=0; $i $total; $i++) { $fileName = $_FILES['userfile']['name'][$i]; $tmpName = $_FILES['userfile']['tmp_name'][$i]; $fileSize = $_FILES['userfile']['size'][$i]; $fileType = $_FILES['userfile']['type'][$i]; $position=$i+1; $img_url = images/$customer_id/. basename( $_FILES['userfile']['name'][$i]); if(move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $img_url)) { chmod('images/'.$customer_id, 0777); chmod($img_url, 0777); } with my resize script $image = imagecreatefromjpeg($img_url); if ($image === false) { exit; } // Get original width and height $width = imagesx($image); $height = imagesy($image); // New width and height $new_width = 200; $new_height = 150; // Resample $image_resized = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); Any ideas how to save the imagecopyresampled() to the folder? T -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] Re: outputing image part 2
Hi Ross, Friday, June 15, 2007, 10:40:37 PM, you wrote: Any ideas how to save the imagecopyresampled() to the folder? Call imagepng (or imagejpeg or whatever) and pass it a filename to save the image instead of output it. Check the help files for examples. Cheers, Rich -- Zend Certified Engineer http://www.corephp.co.uk Never trust a computer you can't throw out of a window -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php