Solved

Imagecreatetruecolor() Leaves Black Line

Posted on 2006-11-07
4
287 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
  • 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now