Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unwanted border 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am using the following code to create an on screen image.
The code works ok but the image has a black line down the right hand side and accross the bottom.
I get this result on several machines.

Any clues what may be wrong?

Code:
<?php
$img_name =$_GET['imnam'];
$ranum = $_GET['cod'];
//$img_name = "midad.jpg";
$max_width    = 150; // maximum x aperture  in pixels
$max_height   = 150; // maximum y aperture in pixels
$size=GetImageSize($img_name);
$width_ratio  = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);
 
if($width_ratio >=$height_ratio) 
{
   $ratio = $width_ratio;
}
else
{
   $ratio = $height_ratio;
}
 
$new_width    = ($size[0] / $ratio);
$new_height   = ($size[1] / $ratio);
Header("Content-Type: image/jpeg");
$src_img = ImageCreateFromJPEG($img_name);
$thumb = ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);

$textcolor = imagecolorallocate($thumb, 0, 0, 0);

imagestring($thumb, 4, $new_width- 65, $new_height-120, $ranum, $textcolor);
ImageJPEG($thumb);

ImageDestroy($src_img);
ImageDestroy($thumb);
?>

Keith
 
I am not sure of the syntax for int but googling around shows an exapmle.
I have a added a couple of new lines but the border still shows.
Code:
$new_width    = ($size[0] / $ratio);
$new_height   = ($size[1] / $ratio);
[b]$new_width=(int)$new_width;[/b]
[b]$new_height=(int)$new_height;[/b]
Am I using int correctly?

Keith
 
Tried round and ceil but the border is still there.
I have got round the problem by putting a border round the original but would prefer no border.
I have even re drawn the image but the problem still remains.

Keith
 
I need to display pictures which have white borders so my old problem has come back to haunt me.
Is this the correct way to use the ceil() function?
Code:
$new_width    = ($size[0] / $ratio);
$new_height   = ($size[1] / $ratio);
$new_width=ceil($new_width);
$new_height=ceil($new_height);

Keith
 
This problem is still bugging me.
I was thinking there could be a division problem, but borders appear at all sizes. This is the full code.
Code:
<?php
$siren=$_GET['bleep'];
if($siren > 16){
	$img_name=$_GET['imnam'];
	$max_wid=$_GET['maxwid'];
	$max_ite=$_GET['maxhi'];
	$max_width    = $maxwid; // maximum x aperture  in pixels
	$max_height   = $maxhi; // maximum y aperture in pixels
	$size=GetImageSize($img_name);
	$width_ratio  = ($size[0] / $max_width);
	$height_ratio = ($size[1] / $max_height);
	if($width_ratio >=$height_ratio) 
	{
	   $ratio = $width_ratio;
	}
		else
	{
	   $ratio = $height_ratio;
	}
	$new_width    = ($size[0] / $ratio);
	$new_height   = ($size[1] / $ratio);
	$new_width=ceil($new_width);
	$new_height=ceil($new_height);
	$src_img = ImageCreateFromJPEG($img_name);
	$thumb = ImageCreateTrueColor($new_width,$new_height);
	ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);


	ImageJPEG($thumb);

	ImageDestroy($src_img);
	ImageDestroy($thumb);
}
?>
I assume that ceil should take care of the non-integer problem but what else could be causing the bottom and right borders?


Keith
 
some things to try:

cast the divisions to double
Code:
    $width_ratio  = (double) ($size[0] / $max_width);
    $height_ratio = (double) ($size[1] / $max_height);

rewrite this bit:
Code:
  $new_width=ceil($new_width);
    $new_height=ceil($new_height);
    $src_img = ImageCreateFromJPEG($img_name);
    $thumb = ImageCreateTrueColor($new_width,$new_height);
    ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
to be
Code:
    $src_img = ImageCreateFromJPEG($img_name);
    $thumb = ImageCreateTrueColor($new_width,$new_height);
    ImageCopyResampled($thumb, $src_img, 0,0,0,0,$new_width,$new_height,$size[0],$size[1]);
[/copy]
sfaik you do not need to worry about feeding not integer values to imagecopyresampled.  it recasts values internally as needed.
 
That's brilliant - problem solved.
Thanks for your help

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top