PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Jul 22, 2019 7:50 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: GD
PostPosted: Thu Oct 18, 2007 1:22 am 
Offline
Forum Contributor

Joined: Sat Aug 28, 2004 12:25 am
Posts: 131
Hi,

I am trying to add a border to my images as they are uploaded. The code I have created seems to work but creates a file on the server with names similar to:

Resource id #18

Inside the file is:

Syntax: [ Download ] [ Hide ]
ÿØÿà

ÿÛ

ÿÄ

%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòó

ôõö÷øùúÿÄ

ÿÄ

$4á%ñ&'
()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêò

óôõö÷øùúÿÚ

Ì+å…


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 6:01 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com


Top
 Profile  
 
 Post subject: Choose the Right Board
PostPosted: Thu Oct 18, 2007 8:13 am 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana

_________________
- A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 3:05 pm 
Offline
Forum Contributor

Joined: Sat Aug 28, 2004 12:25 am
Posts: 131


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 4:16 pm 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6446
Location: 53.01N x 112.48W

_________________
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 4:30 pm 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
It's pretty awful to be honest:

1. You're not checking things work correctly. You're not bothering to check an incoming image actually is a JPEG before loading it with imagecreatefromjpeg() for example.

2. You're not catching errors ... Should someone try to load a PNG file for example the script will fail without doing anything about telling you or creating a placeholder image.

3. You're opening the same image twice. That's a waste of time, especially for a CPU hungry function like imagecreatefromjpeg(). Open it once and reuse it.

4. You're populating an array with the details of the image you're loading ($dimensions) but then you're not using the information. That's wasteful too.

5. You've hardcoded parts of filenames (the "tb_" bit). If you (or the client) decide that you want them to be called something different you'll have to edit the script, or multiple scripts if you're using the same code elsewhere.

6. You're opening a jpeg, resizing it, overwriting the original, then opening it again, adding borders, then overwriting it again. It's a waste of time, you might as well remove the step where you save it in the middle. If you really have to save an image that you're only going to use in a PHP script it's preferable to use imagegd2() to save it, the gd2 format is much quicker to open making your script more efficient.

7. You're using 100 quality on imagejpeg() on the final output image. There's very little difference in quality from, say, 80 but there's a pretty big difference in file size. You're wasting bandwidth and disk space.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sun Jan 27, 2008 10:50 pm 
Offline
Forum Newbie

Joined: Sun Jan 27, 2008 10:24 pm
Posts: 2


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group