Hi,
My code has been working fine until just recently when this error message just started popping up....

Warning: imagecreate(): Invalid image dimensions

Does anyone know what this means, how I can fix it and why it has popped up out of the blue all of a sudden ?

cheers

    Some servers that have PHP installed don't support the imagecreate() function.

    However, that would produce a different error. Is it possible that you put in a non-numerical character in the function, or put quotes in?

    ex:
    imagecreate(10o,100); is bad
    imagecreate("100","100"); is bad too, I think

      Thanks but I cant think why it would be the code considering that it has been working for a year before this problem arose.

        code helps in troubleshooting....

        just saying "I dont know why its worked for X days and now doesnt" doesnt help in troubleshooting....

        show us the problem, most likely we can show you the answer....

          thanks, here is the code.....

          function do_upload($userfile,$image_name) {

          $file = basename($userfile);

          $img_data=getimagesize($userfile);
          $src_w=$img_data[0];
          $src_h=$img_data[1];
          $src_img2=ImageCreateFromJPEG($userfile) or die ("Cannot open source");
          if ($src_w < $src_h) {
          $new_wl = 360;
          $new_hl = 480;}

          else {

          $new_wl = 480;
          $new_hl = 360; }
          $dst_img2=imagecreate($new_wl,$new_hl);
          imagecopyresized($dst_img2,$src_img2, 0, 0, 0, 0, $new_wl, $new_hl, $src_w, $src_h);

          chdir("/home/virtual/site42/fst/var/www/html/ppantiques/stock");
          if ( file_exists($image_name) )
          {
          unlink($image_name);
          }

          imagejpeg($dst_img2,$image_name);

          ImageDestroy($src_img2);
          ImageDestroy($dst_img2);

          }

          function do_upload_thumb($userfile,$image_name) {

          $file = basename($userfile);

          $img_data=getimagesize($userfile);
          $src_w=$img_data[0];
          $src_h=$img_data[1];
          $src_img=ImageCreateFromJPEG($userfile) or die ("Cannot open source");
          if ($src_w < $src_h) {
          $new_w = 90;
          $new_h = 120;}

          else {
          $new_w = 160;
          $new_h = 120;}
          $dst_img=imagecreate($new_w,$new_h);
          $dst_img_large=imagecreate($new_wl,$new_hl);
          imagecopyresized($dst_img,$src_img, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);

          chdir("/home/virtual/site42/fst/var/www/html/ppantiques/stock/thumbnails");
          if ( file_exists($image_name) )
          {
          unlink($image_name);
          }

          imagejpeg($dst_img,$image_name);

          ImageDestroy($src_img);
          ImageDestroy($dst_img);

          }

            are any of those variables POST or GET data? if so, your web host may have upgraded PHP and not informed you.. .if so you need to use $POST['varname'] and $GET['varname'] to get the data... as newer PHP has register globals turned off by default....

              6 days later

              I have checked with my Hosy and say that they have not upgraded their version of Php....

              I am still getting the error...

              Warning: imagecreate(): Invalid image dimensions.

              Any other ideas ???

              Thanks

                I see this being a potential problem...

                imagecopyresized($dst_img,$src_img, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);

                you are saying X Y 0 0 H W 0 0..... (As I dont see any imagecreate()'s in your code.... )

                  Write a Reply...