Page 1 of 1
Image Type (photo album)
Posted: Mon Mar 07, 2005 3:00 pm
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.
Re: Image Type (photo album)
Posted: Mon Mar 07, 2005 3:08 pm
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("e;."e;, $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.
Posted: Mon Mar 07, 2005 3:08 pm
by smpdawg
There are some good classes on phpclasses.org that would simplify your task.
Re: Image Type (photo album)
Posted: Mon Mar 07, 2005 3:15 pm
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("e;."e;, $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?
Posted: Mon Mar 07, 2005 5:05 pm
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
Posted: Mon Mar 07, 2005 5:19 pm
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?
Posted: Mon Mar 07, 2005 5:27 pm
by feyd
you don't. You call the ImageMagick commands via exec() and such.. typically, I believe.
Posted: Mon Mar 07, 2005 5:38 pm
by ast3r3x
Ok thanks...I should be good from here out.
Posted: Wed Mar 16, 2005 8:53 am
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]
Posted: Wed Mar 16, 2005 10:12 am
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..
Posted: Wed Mar 16, 2005 10:26 am
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?
Posted: Wed Mar 16, 2005 11:07 am
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.
Posted: Wed Mar 16, 2005 11:11 am
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.