Solved

Imagecreatetruecolor() Leaves Black Line

Posted on 2006-11-07
4
293 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
The viewer will learn how to dynamically set the form action using jQuery.

696 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