Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Imagecreatetruecolor() Leaves Black Line

Posted on 2006-11-07
4
Medium Priority
?
296 Views
Last Modified: 2006-11-18
Ive been using the GD function imagecreatetruecolor() to resize images on the server and it does the job, but not entirely satisfactorily.

First the output can be quite rough, but the really disturbing habit it has how it leaves a black line to the right and the bottom of resized images.

How do I get it to stop doing that?
0
Comment
Question by:ziche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 17888532
Make sure your resize script rounds up and does not round down when resizing images.

-r-
0
 

Author Comment

by:ziche
ID: 17888579
Im a bit rusty with my php skills, here is my size calculation code:

      if ($old_width > $old_height)
      {
            $new_width = $MAX_WIDTH;
            $new_height = ($old_height / $old_width) * $new_width;
      } else {
            $new_height = $MAX_HEIGHT;
            $new_width = ($old_width / $old_height) * $new_height;
      }

Where how do I include rounding up functionality?
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 400 total points
ID: 17888583
try

     if ($old_width > $old_height)
     {
          $new_width = $MAX_WIDTH;
          $new_height = ceil(($old_height / $old_width) * $new_width);
     } else {
          $new_height = $MAX_HEIGHT;
          $new_width = ceil(($old_width / $old_height) * $new_height);
     }

-r-
0
 

Author Comment

by:ziche
ID: 17888665
Thanks Roonaan.

You are the one!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question