Solved

Imagecreatetruecolor() Leaves Black Line

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 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