Image Type (photo album)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Image Type (photo album)

Post by ast3r3x »

I need to create a script that resizes images on the fly for a photo album. I am having a little difficulty because I want to output a thumbnail of the images but they could be different file formats.

Is there anyway to detect the file format or work with images other than jpg/gif/bmp/png? I guess maybe this is just a limitation of PHP, but I'd like my photo album to be as accommodating as possible.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Re: Image Type (photo album)

Post by qads »

ast3r3x wrote:.......I guess maybe this is just a limitation of PHP......
Nope, thats just you =).

Code: Select all

function file_ext($filename)
{
$exp = explode(&quote;.&quote;, $filename);
return $expїsizeof($exp)-1];
}
//sample
echo file_ext('some.image.dot.jpg');
the above will tell you extension the file has, there are other ways, but this will do.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

There are some good classes on phpclasses.org that would simplify your task.
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Re: Image Type (photo album)

Post by ast3r3x »

qads wrote:
ast3r3x wrote:.......I guess maybe this is just a limitation of PHP......
Nope, thats just you =).

Code: Select all

function file_ext($filename)
{
$exp = explode(&quote;.&quote;, $filename);
return $expїsizeof($exp)-1];
}
//sample
echo file_ext('some.image.dot.jpg');
the above will tell you extension the file has, there are other ways, but this will do.
Haha, no no, I know how to get the file extension, and then the type. What I'm saying is...to my (basic I'll admit) understanding of GD is that when you create an image from a file, you need to do imagecreatefrompng/imagecreatefromgif...ect. But how would you load and scale an image that is a psd or another format?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

gd cannot load any other formats outside the common ones it handles. If you need more substantive handling, you need something like ImageMagick: http://imagemagick.sf.net
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post by ast3r3x »

OK, thanks!

Now...hopefully this is simple, how would I go about appending these C APIs to PHP? I would think since PHP is a C compiled language that it wouldn't be too difficult right?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you don't. You call the ImageMagick commands via exec() and such.. typically, I believe.
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post by ast3r3x »

Ok thanks...I should be good from here out.
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post by ast3r3x »

Ok...so I got it working, and it works great, I even figured out a nice way to clear my thumbnails that aren't in use.

See

However, take keen note to how the text looks...pretty good, it's imposed over the image.

Now using the same function, on the same images, I want to know why these images look different. I guess it could be different versions of GD, but should it really matter?[/url]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the "text" doesn't appear over the image in my browser (Firefox 1.0.1)

It appears you are generating all the thumbnails on the fly, always.. you may want to think about caching the thumbnails to save on processing loads when being viewed by multiple parties..
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post by ast3r3x »

If you grab the image and move it, you'll see the text is part of the image. I decided that the text would be easier to see on a solid background, because you can't control the colors in the picture, so depending, it can be very difficult to read.

I am storing the thumbnails so they don't have to be recreated unless either the thumbnailing script or the original image changes.

The reason you'll see a slow load time (specifically on swigg.net) is because it's hosted off of my computer for the time being.

Do you notice how the text looks different on each page?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the difference is fairly small.. with only having a slightly better rendering on the first link. It could easily be due to a difference in GD versions.
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post by ast3r3x »

Yeah, thats what I figured, but I was hoping it was, as usual, something I was doing. It's just so frustrating because the one page looks good, adn the other, the text looks ugly as sin. Ok, I guess I can finally let this thread die now.
Post Reply