Jump to content


Photo

Uploading Images


  • Please log in to reply
2 replies to this topic

#1 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 20 September 2006 - 02:05 PM

The Below code is what i am using to upload and resize images. now i have tried uploading 2 images one of them was 300 x 300 and another was 200 x 200 and neither uploaded it cam up with an error saying it was divsion by 0 :S can anyone see why?

$uploaddir = "/public_html/player_images/";
    

    $pext = getFileExtension($imgfile_name);
    $pext = strtolower($pext);
    if (($pext != "jpg")  && ($pext != "jpeg"))
    {
        print "<h1>ERROR</h1>Image Extension Unknown.<br>";
        print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>";
        print "The file you uploaded had the following extension: $pext</p>\n";

      
        unlink($imgfile);
        exit();
    }




  
    $imgsize = GetImageSize($imgfile);


    if (($imgsize[0] > 200) || ($imgsize[1] > 200))
    {

        $tmpimg = tempnam("/tmp", "MKUP");


             1. decompress jpeg image to pnm file (a raw image type)
             2. scale pnm image
             3. compress pnm file to jpeg image

        
   
        system("djpeg $imgfile >$tmpimg");
        


        system("pnmscale -xy 200 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile");

  
        unlink($tmpimg);

    }

 
    $final_filename = str_replace(" ", "_", $imgfile_name);
    $newfile = $uploaddir/$final_filename;
    
   
    if (is_uploaded_file($imgfile))
    {

       if (!copy($imgfile,"$newfile"))
       {

          print "Error Uploading File.";
          exit();
       }
     }

 
    unlink($imgfile);

    
    echo "<img src=\"/public_html/player_images/$final_filename\">";


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 September 2006 - 02:12 PM

heres an example how to resize an image ok.

gd must be enabled in the php.ini



<?php

// Load image
$image = open_image('flower.jpg');
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height
$new_width = 150;
$new_height = 100;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 20 September 2006 - 02:30 PM

so where in my code would that go? the code i used was an example off of a website along with the functions off of php.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users