473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use GD library in php to resize an image

I am creating a website that searches for photos. I found that functions in GD library are capable of resizing images through pre-created functions. I have created a test script to read and resize an image. It theoretically opens and reads an image to a variable then uses the read image to resize the image and display it before closing the file. The code I wrote is:

**before going on: I used header and specified the type but was told that this information was passed. When I checked the type it did return image/jpeg which is why this truly stumps me. What is returned by fopen and fread seems to be symbolic still.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <?php
  4. $percent=0.5;
  5. $filename="http://bytes.com/images/dtown.jpg";
  6. $fp=fopen($filename,"rb");
  7. $file=fread($fp,filesize($filename));
  8. list($width,$height)=getimagesize($file);
  9. $new_width=$width*$percent;
  10. $new_height=$height*$percent;
  11. $image_p=imagecreatetruecolor($new_width,$new_height);
  12. $image=imagecreatefromjpeg($file);
  13. imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);
  14. imagejpeg($image_p,null,100);
  15. fclose($fp);
  16. ?>
  17. </body>
  18. </html>
  19.  
However, I continue to get
Expand|Select|Wrap|Line Numbers
  1. Warning: getimagesize(ÿØÿà) [function.getimagesize]: failed to open stream: No such file or directory in C:\Inetpub\vhosts\dumountaineer.com\httpdocs\dbimages\test.php on line 8
  2.  
  3. Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Inetpub\vhosts\dumountaineer.com\httpdocs\dbimages\test.php on line 11
  4.  
  5. Warning: imagecreatefromjpeg(ÿØÿà) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\Inetpub\vhosts\dumountaineer.com\httpdocs\dbimages\test.php on line 12
  6.  
  7. Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\Inetpub\vhosts\dumountaineer.com\httpdocs\dbimages\test.php on line 13
  8.  
  9. Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\Inetpub\vhosts\dumountaineer.com\httpdocs\dbimages\test.php on line 14
  10.  
Apparently, it is reading the file in symbols still. I specified binary in the fopen function with "rb".

Is there a way to make this work? I am using a Windows Parallels Plesk Server and the symbols don't look like binary.
***I tried without opening the file and just linking to it and the entire image was just symbols. The PHP manual recommends using fopen but the symbols keep appearing. I have used fread and readfile to try and open the image. All help is appreciated.
Dec 3 '10 #1

✓ answered by Scott Evans

I ended up finding a workaround. I cannot use some of the functions in my account or access my .ini file. I was able to use list(width,height) and get_image_size to come up with a solution.

1 2136
I ended up finding a workaround. I cannot use some of the functions in my account or access my .ini file. I was able to use list(width,height) and get_image_size to come up with a solution.
Dec 30 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Julia Briggs | last post by:
I am struggling to create a PHP function that would take a specified image (JPG, GIF or PNG) from a link, and resize it down to a thumbnail so it will always fit in a 200x250 space. I am hoping...
1
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
1
by: David | last post by:
Hello. How can I resize image in Bitmap object?
3
by: DichkoSoft | last post by:
Dear All I don't know haw i resize inage in VB.NET I want load image with size 800x600 then rezize it to 80x60 pixels and save to a file. -- DichkoSoft
2
by: Adam J Knight | last post by:
Hi all, I am trying resize an image using the following code. //resize image System.Drawing.Image ImageUpload =...
1
by: Arjen | last post by:
Hi, I want to resize an image on my server. I tried a lot of samples... but all the time it does resize and saves the images but I can not view the image insize a webbrowser. With an...
6
by: Bob Bedford | last post by:
Hi all, I've a classic upload form where people may select images on their computer to send on my website. Since this is done by people not very confortable with computers, some sent pictures...
6
by: Bob Bedford | last post by:
Hi all, I've to resize uploaded images with the "imagecopyresampled" but when I've images quite large (common those days) I reach the 16mb limits of the ISP. How can I fix this ? I absolutely...
3
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
how can i reesize an image so its quallity will stay the same as the original 1? thnaks in advance peleg
22
by: simon2x1 | last post by:
i have an image which width is 213 and height is 200 when i echo the image and i resize it echo "<img src='company/$present' width='70' height='68'/>"; the image was not as clear as when it was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.