Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Text is blurring.

images php coding issues or problems here.

Moderators: macek, egami, gesf

Text is blurring.

Postby Shiv » Tue Oct 25, 2005 1:23 am

Hi..

when I use imagecolorallocate() . There seems to be blurring around the text when previewing. Is any idea to remove it.
User avatar
Shiv
php-forum Active User
php-forum Active User
 
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA

Postby ruturajv » Tue Oct 25, 2005 7:36 pm

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 ?
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby Shiv » Tue Oct 25, 2005 9:23 pm

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.
User avatar
Shiv
php-forum Active User
php-forum Active User
 
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA

Postby tamill » Wed Oct 26, 2005 6:08 pm

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
tamill
New php-forum User
New php-forum User
 
Posts: 8
Joined: Tue Aug 23, 2005 5:55 pm

Postby ruturajv » Wed Oct 26, 2005 10:57 pm

post your code, that will actually generate an image, so that we can test and let you know.
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby Shiv » Wed Oct 26, 2005 11:50 pm

Code: Select all

<?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
User avatar
Shiv
php-forum Active User
php-forum Active User
 
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA

Postby ruturajv » Thu Oct 27, 2005 12:31 am

can you post the image as well, it seems that code is alright.
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby Shiv » Thu Oct 27, 2005 12:45 am

Image is looking alright when I save it. This problem only occurs when it displays resource image in browser.
User avatar
Shiv
php-forum Active User
php-forum Active User
 
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA

Postby ruturajv » Thu Oct 27, 2005 7:35 pm

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: Select all
<html>
<body>
<img src="/page-where-img-generated.php?someparams" />
</body>
</html>
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby Shiv » Thu Oct 27, 2005 9:23 pm

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
User avatar
Shiv
php-forum Active User
php-forum Active User
 
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA

Postby ruturajv » Fri Oct 28, 2005 11:04 pm

thats it,
instead of displaying the image directly to the browser, display the image using img tag, that will solve the problem.
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby Alexej Kubarev » Sat Oct 29, 2005 2:33 am

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.
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.