Text is blurring.

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Hi..

when I use imagecolorallocate() . There seems to be blurring around the text when previewing. Is any idea to remove it.
 
I don't think there is blurring...
what it may be you are seeing a scaled image by the browser,
eg. the browsers scale a large image to fit the screen, that creates a blur (actually dithered) effect.
Is this the problem ?
 
I hope u r right but i see this effect (blurring or dithering) of text so if u or other one find solution plz give it to me.
 
i guess u r using .jpg extension.

If u wanna clear picture please try the .png format.

i will look more clear i guess.

please try & say ur comment
 
post your code, that will actually generate an image, so that we can test and let you know.
 
Code:
<?php
/*
Created by : Viral B. Upadhyaya
Created Date : Monday, 22 August 2005
*/

session_start();
include("../inc/general/common.inc");
define("USER_TEMPLATE_DIR","../user_temp_template");
define("FONT_DIR","../admin/fontfiles");


if(!empty($_SESSION['usertemplate']))
{
	
	
	$usertplimagename = $_SESSION['ssnusertplimagename'];
	$im = imagecreatefromjpeg(USER_TEMPLATE_DIR."/".$usertplimagename);
	
	if($im)
	{
		
		/********************************************************************************************************************/
		
		if(get_param("islogo") == 1 && get_param("lx") != "" && get_param("ly") != "")
		{
			$islogo = get_param("islogo");
			$logox = get_param("lx");
			$logoy = get_param("ly");
			
			if(!empty($_SESSION['userid']))
			{
				$substremail = substr($_SESSION['useremail'],0,strpos($_SESSION['useremail'],"@"));
				$userid = $substremail.$_SESSION['userid'];			
			}
			else
			{		
				$userid = "temp";
			}
						
			if(isset($_SESSION['ssnlogo']) && $_SESSION['ssnlogo'] != "")
			{
							
				if(strstr($_SESSION['ssnlogo'],"logo_temp_"))
				{
					$logofilename = "../user_upload_images/".$_SESSION['ssnlogo'];
				}
				elseif(strstr($_SESSION['ssnlogo'],"logo_".$userid."_"))
				{
					$logofilename = "../user_upload_images/".$_SESSION['ssnlogo'];
				}
				else
				{
					$logofilename = "../admin/logoimages/".$_SESSION['ssnlogo'];
				}
				
				$mainlgim = imagecreatetruecolor(75,75);
				list($src_width,$src_height,$src_type) = getimagesize($logofilename);
				
				if($src_type == 1)
				{
					$lgim = imagecreatefromgif($logofilename);
				}
				elseif($src_type == 2)
				{	
					$lgim = imagecreatefromjpeg($logofilename);
				}
				
				if($lgim)
				{
					imagecopyresampled($mainlgim,$lgim,0,0,0,0,75,75,$src_width,$src_height);
				}
				
				if($mainlgim)
				{
					//imagecopymerge($im,$lgim,$logox,$logoy,0,0,$src_width,$src_height,100);
					imagecopymerge($im,$mainlgim,$logox,$logoy,0,0,75,75,100);
					imagedestroy($lgim);
					imagedestroy($mainlgim);
				}
			}	
		}
		
		/********************************************************************************************************************/
		
		/**********************************************************************************************************************/
		$usertpl_array = $_SESSION['usertemplate'];
		
	
		foreach($usertpl_array as $key => $row)
		{			
			$title_array = $usertpl_array['tpltitle_value'];
			$fontcolor_array = $usertpl_array['tplfontcolor'];
			$fontface_array = $usertpl_array['tplfontface'];
			$fontfile_array = $usertpl_array['tplfontfile'];
			$fonttype_array = $usertpl_array['tplfonttype'];
			$fontsize_array = $usertpl_array['tplfontsize'];
			$x_pos_array = $usertpl_array['tplx_pos'];
			$y_pos_array = $usertpl_array['tply_pos'];
		}
		
		$titlecount = count($title_array);
		
		for($i=0;$i<$titlecount;$i++)
		{
			
			/*************************/
			/*if($fontcolor_array[$i] == "black")
			{
				$fontcolor_array[$i] = imagecolorallocate($im,0X00,0X00,0X00);
			}
			elseif($fontcolor_array[$i] == "white")
			{
				$fontcolor_array[$i] = imagecolorallocate($im,0XFF,0XFF,0XFF);
			}
			elseif($fontcolor_array[$i] == "red")
			{
				$fontcolor_array[$i] = imagecolorallocate($im,0XFF,0X00,0X00);
			}
			elseif($fontcolor_array[$i] == "green")
			{
				$fontcolor_array[$i] = imagecolorallocate($im,0X00,0XFF,0X00);
			}
			elseif($fontcolor_array[$i] == "blue")
			{
				$fontcolor_array[$i] = imagecolorallocate($im,0X00,0X00,0XFF);
			}
			elseif($fontcolor_array[$i] == "yellow")
			{
				$fontcolor_array[$i] = imagecolorallocate($im,0XFF,0XFF,0X00);
			}
			elseif($fontcolor_array[$i] == "gray")
			{
				$fontcolor_array[$i] = imagecolorallocate($im,0X66,0X66,0X66);
			}*/
			
			$fontcolor_array[$i] = chunk_split($fontcolor_array[$i],2,":");
			$colcd = split(":",$fontcolor_array[$i]);
			$fontcolor_array[$i] = imagecolorallocate($im,hexdec("0X".$colcd[0]),hexdec("0X".$colcd[1]),hexdec("0X".$colcd[2]));
			
						
			/************************/
						
			
			//imagettftext($im,$fontsize_array[$i],0,$x_pos_array[$i],$y_pos_array[$i],$fontcolor_array[$i],FONT_DIR."/".$fontfile_array[$i],$title_array[$i]);
			imagettftext($im,$fontsize_array[$i],0,$x_pos_array[$i],$y_pos_array[$i],$fontcolor_array[$i],FONT_DIR."/".$fontfile_array[$i],stripslashes($title_array[$i]));
		}
		/********************************************************************************************************************/
		
		
		
		$sql = "";
		$sql = "select templateid, tempwidth, tempheight from tbltemplatemst where templateid=".$_SESSION['chosentemplate']['tplid'];
		$db->query($sql);
		$db->next_record();
			
		$tplwidth = $db->f('tempwidth');
		$tplheight = $db->f('tempheight');
		
		$zoom = get_param("zoom");
		if($zoom != "" && $zoom != 0 && $zoom >= 50 && $zoom <=150)
		{
			$tplwidth = $tplwidth * ($zoom/100);
			$tplheight = $tplheight * ($zoom/100);
		}		
		
		
		$mainimage = imagecreatetruecolor($tplwidth,$tplheight);
		list($width,$height) = getimagesize(USER_TEMPLATE_DIR."/".$usertplimagename);
		imagecopyresampled($mainimage,$im,0,0,0,0,$tplwidth,$tplheight,$width,$height);		
		
		//imagejpeg($im);
		imagejpeg($mainimage);
		imagedestroy($mainimage);
		imagedestroy($im);
	}
}

?>


Please look at imagecolorallocate at line 141
 
can you post the image as well, it seems that code is alright.
 
Image is looking alright when I save it. This problem only occurs when it displays resource image in browser.
 
just try to keep the mouse over the image on the browser...
IE // it should show 4 small images on top right, and 1 expand image at bottom right
Mozilla // it should show a zoom icon
if any of the above is true that means the browser is trying to resize the image to fit the screen as I had told you earlier

In that case, you show the image in an IMG tag rather than just a direct link that generates the image so...

Code:
<html>
<body>
<img src="/page-where-img-generated.php?someparams" />
</body>
</html>
 
I m not giving height and width to resize. U could c in my code i use imagecopyresampled.
Dont worry when i generate PDF and image (jpg) physically it is perfect nice looking :)
But i have to something to show user a clear text. By the way thanX
 
thats it,
instead of displaying the image directly to the browser, display the image using img tag, that will solve the problem.
 
I think you didnt really hear what ruturajv was saying about displaying images directly (when Content-Type header is set to image/jpeg or simmilar)

Browsers resize the image when its bigger then the window size, some times they even do it when its a bit smaller.
 
Back
Top