Solved

Imagecreatetruecolor() Leaves Black Line

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 …
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

23 Experts available now in Live!

Get 1:1 Help Now