473,386 Members | 1,830 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,386 software developers and data experts.

How to resize selected image from database?

123 100+
The code below will resize an image to 50*50 but whenever i select the name of the image in my database and put it like these $filename = 'folder/$imagename'; it does not work how can i fix these.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $filename = 'folder/Aizen.jpg';
  3.  
  4. $width = 50;
  5. $height = 50;
  6.  
  7. header('Content-type: image/jpeg');
  8. list($width_orig, $height_orig) = getimagesize($filename);
  9.  
  10. $ratio_orig = $width_orig/$height_orig;
  11.  
  12. if ($width/$height > $ratio_orig) {
  13.    $width = $height*$ratio_orig;
  14. } else {
  15.    $height = $width/$ratio_orig;
  16. }
  17.  
  18. $image_p = imagecreatetruecolor($width, $height);
  19. $image = imagecreatefromjpeg($filename);
  20.  
  21. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  22. imagejpeg($image_p, null, 100);
  23. ?>
  24. <img src="<?= $filename ?>" alt="" />
  25.  
  26.  
  27.  
Feb 2 '11 #1
1 2075
Markus
6,050 Expert 4TB
Does that file exist?
Feb 2 '11 #2

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

Similar topics

2
by: Giovanni | last post by:
Hello, I need to insert a resized image in a html page. I know that using the html IMG tag it is possible to set the height and width attributes, with no need of php (or server-side...
3
by: querypk | last post by:
Hi I would like to know how to resize an Image without using python Imaging library.
8
by: Michael Satterwhite | last post by:
I'm opening a page that has a single image on it. I'd like to resize the window containing the image to the size of the image (slightly larger OK, not smaller). The width isn't a problem, but the...
6
by: bissatch | last post by:
Hi, I have a collection of images stored in a DB. They are there for the purpose of a news system. When the user views the homepage it will diplay cropped versions of the news where the user...
0
by: funcSter | last post by:
I've got this bit of code: Image origImage = Image.FromFile("temp.jpg"); Image newImage = new Bitmap(objNewSize.Width, objNewSize.Height, origImage.Pixelformat); Graphics objGraphic =...
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
2
by: Shapper | last post by:
Hello, In each record of an ASP.Net Repeater I have an image which original size is 200px width and with a height which can vary from record to record. How can I resize each image to 50px and...
2
by: Carl Gilbert | last post by:
Hi I am looking for either a component or technique to allow me to do the following: * Provide a panel with a background image * Resize the image to best fit the panel to maintain aspect...
1
by: joe | last post by:
Any articles relating with Uploading images files to server and resize the image by asp.net 2.0
8
by: Robert S | last post by:
I am writing an image viewer. I want to be able to resize the image so that it always fits within a window of given height and width. I've tried a couple of these from the web, but the don't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.