Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to find size (in bytes) of an image using the GD image resource?
I would like to be able to determine the size (in bytes) of a file and
re-adjust before output. Is this possible?

Norm

--
Avatar hosting at www.easyavatar.com



Report this thread to moderator Post Follow-up to this message
Old Post
Norman Peelman
07-30-04 01:55 PM


Re: How to find size (in bytes) of an image using the GD image resource?
"Norman Peelman" <npeelman@cfl.rr.com> wrote in message
news:iqoOc.413$Hu2.378@tornado.tampabay.rr.com...
>   I would like to be able to determine the size (in bytes) of a file and
> re-adjust before output. Is this possible?
>
> Norm
>
> --
> Avatar hosting at www.easyavatar.com
>
>

No need to use GD, just use this:


function my_filesize($file) {
if(!is_file("./".$file)) return "0 KB";
$kb = 1024;         // Kilobyte
$mb = 1024 * $kb;   // Megabyte
$gb = 1024 * $mb;   // Gigabyte
$tb = 1024 * $gb;   // Terabyte

$size = filesize($file);

if($size < $kb) {
return $size." B";
}
else if($size < $mb) {
return round($size/$kb,2)." KB";
}
else if($size < $gb) {
return round($size/$mb,2)." MB";
}
else if($size < $tb) {
return round($size/$gb,2)." GB";
}
else {
return round($size/$tb,2)." TB";
}
}


Regards
Richard Grove



Report this thread to moderator Post Follow-up to this message
Old Post
Žed Eye Media - Richard Grove
07-30-04 08:55 PM


Re: How to find size (in bytes) of an image using the GD image resource?
On Fri, 30 Jul 2004 09:21:18 GMT, "Norman Peelman" <npeelman@cfl.rr.com> wro
te:

>  I would like to be able to determine the size (in bytes) of a file and
>re-adjust before output. Is this possible?

If you mean determine the size of the file it _would_ create, you can't
without encoding it to somewhere, either memory or a temporary file.

You could capture output (ob_start()) etc., use imagepng/jpeg/whatever, and
save the output buffer to a variable and use strlen to work out the size.

Or save to a file anyway, and use filesize(), and regenerate it if you don't
like the size.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk         / http://www.andyhsoftware.co.uk/space

Report this thread to moderator Post Follow-up to this message
Old Post
Andy Hassall
07-30-04 08:55 PM


Re: How to find size (in bytes) of an image using the GD image resource?
"Andy Hassall" <andy@andyh.co.uk> wrote in message
 news:ip3lg0lgo033sd54g7dnqv9crq857e2oo8@
4ax.com...
> On Fri, 30 Jul 2004 09:21:18 GMT, "Norman Peelman" <npeelman@cfl.rr.com>
wrote:
> 
>
>  If you mean determine the size of the file it _would_ create, you can't
> without encoding it to somewhere, either memory or a temporary file.
>
>  You could capture output (ob_start()) etc., use imagepng/jpeg/whatever,
and
> save the output buffer to a variable and use strlen to work out the size.
>
>  Or save to a file anyway, and use filesize(), and regenerate it if you
don't
> like the size.
>
> --
> Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
> http://www.andyh.co.uk         / http://www.andyhsoftware.co.uk/space

Thanks Andy, you understood what I meant... my mistake I should have said
'image' instead of 'file'.  I'll look into the ob_* functions but wich do
you think would be faster (or easier)?

Norm
--
Avatar hosting at www.easyavatar.com



Report this thread to moderator Post Follow-up to this message
Old Post
Norman Peelman
07-31-04 01:55 AM


Re: How to find size (in bytes) of an image using the GD image resource?
On Fri, 30 Jul 2004 22:04:36 GMT, "Norman Peelman" <npeelman@cfl.rr.com> wro
te:

>"Andy Hassall" <andy@andyh.co.uk> wrote in message
> news:ip3lg0lgo033sd54g7dnqv9crq857e2oo8@
4ax.com... 
>wrote: 
>
>Thanks Andy, you understood what I meant... my mistake I should have said
>'image' instead of 'file'.  I'll look into the ob_* functions but wich do
>you think would be faster (or easier)?

I would guess ob_* would be faster, writing to a file would be easier,
although I wouldn't have thought there a massive difference between the two.

If you're writing out to a file in the end anyway, and more often than not y
ou
get reasonable settings the first time, I'd probably tend towards writing
straight to a file.

If you're outputting to the browser rather than saving to disk, I'd tend
towards the ob_* solution.

As ever, the only answer to what's best is It Depends (tm).

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk         / http://www.andyhsoftware.co.uk/space

Report this thread to moderator Post Follow-up to this message
Old Post
Andy Hassall
07-31-04 01:55 AM


Re: How to find size (in bytes) of an image using the GD image resource?
"Andy Hassall" <andy@andyh.co.uk> wrote in message
 news:ip3lg0lgo033sd54g7dnqv9crq857e2oo8@
4ax.com...
> On Fri, 30 Jul 2004 09:21:18 GMT, "Norman Peelman" <npeelman@cfl.rr.com>
wrote:
> 
>
>  If you mean determine the size of the file it _would_ create, you can't
> without encoding it to somewhere, either memory or a temporary file.
>
>  You could capture output (ob_start()) etc., use imagepng/jpeg/whatever,
and
> save the output buffer to a variable and use strlen to work out the size.
>
>  Or save to a file anyway, and use filesize(), and regenerate it if you
don't
> like the size.
>
> --
> Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
> http://www.andyh.co.uk         / http://www.andyhsoftware.co.uk/space

Andy,

Got it figured out with ob_start(), ob_get_length(), and ob_end_flush().
Thanks for the help!

Norm
--
Avatar hosting at www.easyavatar.com



Report this thread to moderator Post Follow-up to this message
Old Post
Norman Peelman
07-31-04 01:55 AM


Re: How to find size (in bytes) of an image using the GD image resource?
"Andy Hassall" <andy@andyh.co.uk> wrote in message
 news:e2ilg0ln2jcumviea4q8kcj0mj9thjagnl@
4ax.com...
> On Fri, 30 Jul 2004 22:04:36 GMT, "Norman Peelman" <npeelman@cfl.rr.com>
wrote:
> 
<npeelman@cfl.rr.com> 
and 
can't 
imagepng/jpeg/whatever, 
size. 
>
>  I would guess ob_* would be faster, writing to a file would be easier,
> although I wouldn't have thought there a massive difference between the
two.
>
>  If you're writing out to a file in the end anyway, and more often than
not you
> get reasonable settings the first time, I'd probably tend towards writing
> straight to a file.
>
>  If you're outputting to the browser rather than saving to disk, I'd tend
> towards the ob_* solution.
>
>  As ever, the only answer to what's best is It Depends (tm).
>
> --
> Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
> http://www.andyh.co.uk         / http://www.andyhsoftware.co.uk/space

I'm coming from a database (blob field) and going straight to browser
(client) output and I didn't want to have to go to the filesystem. The ob_*
funcs worked like a charm.

--
Avatar hosting at www.easyavatar.com



Report this thread to moderator Post Follow-up to this message
Old Post
Norman Peelman
07-31-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:30 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.