LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-05-2005, 08:28 AM   #1
devfreak
Member
 
Registered: Mar 2004
Location: Maine
Distribution: gentoo 2004.1, ubuntu 4.10, FC3
Posts: 97

Rep: Reputation: 15
php and gd (image functions)


for some reason I can't get any of PHP's image functions to work on my company's dedicated server. If someone who has had a headache with this could share my headache with me, it would be awesome. Here's my phpinfo()

http://www.saunders-usa.com/test.php

And just for reference, here's the phpinfo() of a server that I know can run them, because they were posting example scripts:

http://smallcapitalbusiness.com/phpinfo.php

I have gd installed and enabled, so I don't know what the deal is. Basically instead of shrinking images that the other site can shrink, it gives a broken image (or in firefox, says that the image has problems)
 
Old 05-11-2005, 05:17 PM   #2
polrus
Member
 
Registered: Oct 2004
Location: Poland
Distribution: yoper
Posts: 53

Rep: Reputation: 15
i think ur shrinking script may be wrong

if gd wasnt properly installed You would get an error in php about some functions not beeing defined (for example with imagecreatefromjpeg function form the script bellow)

i spend a lot of time playing with shrinking script so if u want You cna see how i do it with my script that displays an image with it's path stored in mysql

as a parameter u give only the image number and the scripts gets the path from mysql table - after that it checks wether there is already a thumbnail-it there's not it generates it and saves it for future use.

so the gallery entry looks like this
(example)

PHP Code:
<a href="galeria.php?strona_obrazka=17&language="><img src="http://centrum.gliwice.pl/~azm/sep/galeria/thumb/obrazek.php?image_path=http://centrum.gliwice.pl/~azm/sep/galeria/DSC_3772copy.jpg" border="0"></a
and the obrazek.php script looks like that

PHP Code:
<?
    
//$image_path paramtr z nazwa pliku i sciezka


    
$thumbnail_name=end(explode('/',$image_path));   
    
$thumbnail=str_replace($thumbnail_name,"thumb/$thumbnail_name",$image_path);
   

 if (!
file_exists("$thumbnail_name"))  
   { 
    
define(IMAGE_BASE'');
    
define(MAX_WIDTH150);
    
define(MAX_HEIGHT150);

    
# Get image location
    //$image_file = str_replace('..', '', $_SERVER['QUERY_STRING']);
    //$image_path = $image_file;

    //echo "<BR>sciezka : $image_path<BR>";
    # Load image
    
    
$img null;
    
$ext strtolower(end(explode('.'$image_path)));
    if (
$ext == 'jpg' || $ext == 'jpeg') {
    
$img imagecreatefromjpeg($image_path);
    } else if (
$ext == 'png') {
    
$img imagecreatefrompng($image_path);
    
# Only if your version of GD includes GIF support
    
} else if ($ext == 'gif') {
    
$img imagecreatefrompng($image_path);
    }

    
# If an image was successfully loaded, test the image for size
    
if ($img)
      {
        
# Get image size and scale ratio
        
$width imagesx($img);
        
$height imagesy($img);
        
$scale min(MAX_WIDTH/$widthMAX_HEIGHT/$height);

        
# If the image is larger than the max shrink it
        
if ($scale 1)
          {
            
$new_width floor($scale*$width);
            
$new_height floor($scale*$height);

            
# Create a new temporary image
            
$tmp_img imagecreatetruecolor($new_width$new_height);
            
//$tmp_img = imagecreate($new_width, $new_height);
            # Copy and resize old image into new image
            
imagecopyresized($tmp_img$img0000,
                         
$new_width$new_height$width$height);
            
imagedestroy($img);
            
$img $tmp_img;
          }
        }

   
# Create error image if necessary
   
if (!$img)
    {
//     $img = imagecreate(MAX_WIDTH, MAX_HEIGHT);
     
$img imagecreatetruecolor(MAX_WIDTHMAX_HEIGHT);
     
imagecolorallocate($img,0,0,0);
     
$c imagecolorallocate($img,70,70,70);
     
imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2);
     
imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);
     }

   
#save to file for future displays
//   @imagejpeg($img,$thumbnail);
   
   # Display the image
   
header("Content-type: image/jpeg");
   
//echo "$thumbnail_name";
   
imagejpeg($img,"$thumbnail_name");
   
   
imagejpeg($img);   
  }
  
  else 
    {
      
$img imagecreatefromjpeg($thumbnail);
      
      if (!
$img)
       {
         
//$img = imagecreate(MAX_WIDTH, MAX_HEIGHT);
         
$img imagecreatetruecolor(MAX_WIDTHMAX_HEIGHT);
          
imagecolorallocate($img,0,0,0);
          
$c imagecolorallocate($img,70,70,70);
          
imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2);
          
imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);
       }
      
      
header("Content-type: image/jpeg");
      
imagejpeg($img); 
    } 
   
?>
let me know if it worked , as creating thumbnails is probably what u wanted to achive
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP about functions djgerbavore Programming 1 11-25-2004 07:14 PM
functions in PHP gaddargarson Programming 3 10-07-2004 02:02 PM
php: array with functions ldp Programming 7 09-22-2004 04:55 PM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM
PHP date functions cmfarley19 Programming 1 10-17-2003 08:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration