hi!

I have images gallery. First i load images on the fly with auto resizing. when I load some images crashed. How i detect this corrupt images and put error massage?

I see this from www.php.net :

<?php
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); / Attempt to open /
if (!$im) { / See if it failed /
$im = imagecreatetruecolor(150, 30); / Create a black image /
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/ Output an errmsg /
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
?>

but i dont know how use this!
Thank you!

    you say load images. what you are you referring to? loading via browser or image program

    perhaps you should verify the uploading of the images

      thank for replay

      I solve the problem. Resize do via browser. When images crashed or missed i call office image! Here is my script:

      <?
      header("Content-type: image/jpeg");

      function loadjpeg($path, $max_x, $max_y) {
      $im = @imagecreatefromjpeg($path);
      if (!$im) {
      $office = 'no_pic.gif';

      // Content type
      header('Content-type: image/gif');

      // Get new dimensions
      list($width, $height) = getimagesize($office);
      $new_width = 100;
      $new_height= 75;

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

      // Output
      imagegif($image_p, null, 100);
      }

      if ($max_x != 0 && $max_y != 0) {
      $x = 100;
      $y= 75;

      if (imagesx($im) != $x || imagesy($im) != $y) {
      $tmp = imagecreatetruecolor($x, $y);
      imagecopyresampled($tmp, $im, 0, 0, 0, 0, $x, $y, imagesx($im), imagesy($im));
      imagedestroy($im);
      $im = $tmp;
      }
      }

      return $im;
      }
      $qwerty="my_image.jpg".$pic;
      $jpg = loadjpeg("$qwerty",150,150);

      //Display new image in browser, quality 50%
      Header("Content-type: image/jpeg");
      imagejpeg($jpg,'',50);

      ?>

      CHEERS!

        Write a Reply...