Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding (.jpg) extension to a file

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
I am not storing file names for images in my database. What I am doing to display an image is just "echo" ID of the record and then add ".jpg" at the end. It works fine, but now I need to do something different. I need to resize the image to create thumbnail. I wrote function that does just that, however I can't make it to work because when I try to maipulate the file, it can't find it. It's obvious because it looks for an "ID.jpg" in my database and I only have "ID."

Now my question is how can I add an extension to to a string for this type of manipulation. In other words I need to do something like this:

$image_name = "$ID + .jpg" //to create for example 12345.jpg
. . . Resize $image_name
. . . Save resized image with name 12345.jpg into /thmbnails directory.

I hope that it makes sence. :)
 
There is a less processor-intensive way to resize graphics.

Most modern browsers, when presented with <IMG> tag &quot;height&quot; and &quot;width&quot; attributes that are different than the actual file, will resize the graphic to fit the set size.

The &quot;gotcha&quot; is that the large image must be downloaded. If you have an image gallery, it would be network-intensive to download a bunch of large images, versus thumbnails.


Anyway, on to your question.

I have a question. How would your script know that it should assign the filename &quot;12345.jpg&quot;? ______________________________________________________________________
TANSTAAFL!
 
If you resize a large image it looks horrible on the screen. Plus as you said both those images have to be downloaded to the user's machine even if they are resized by the browser. So I'd rather create thumbnails on the fly and store them in the directory. In this case if the next person looking for the same item he/she automatically will see stored thumbnail. I am not really concern about space, so storing thumbnails is not an issue. My script looking for an ID number in my database (ex: 1234), after that it ads extension .jpg to it and drops the whole thing into the <img scr=> tag. Very simple, but very efective. If only I knew how to add this &quot;.jpg&quot; to the 1234!!!!
 
Simple concatenation won't do?

$image_name = $ID . &quot;.jpg&quot;;

______________________________________________________________________
TANSTAAFL!
 
I did it a little bit differently, and now it works fine.

$item_number = &quot;1234&quot;;
$ext = &quot;.jpg&quot;;
$full_name = &quot;$item_number$ext&quot;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top