title: php resizing image then cut it in pieces and show it, doesnt work
body: <p>I'm making a website for fun but I cant seem to figure out why this piece of code wont work:</p>
  
  <pre><code>// error control
  ini_set('display_errors', 'On');
  error_reporting(E_ALL | E_STRICT);
  // loading in the image.
  $img = imagecreatefromjpeg(".\image\ons\Ons-foto\mayor.jpg");
  
  if($img != null){
      $width = imagesx($img);
      $heigth = imagesy($img);
      $calw = 134*7;
      $calh = 122*7;
      $newimg = null;
      if($width != null &amp;&amp; $heigth != null){
  
          // a check to see if the image is the right size
  
          if($width &gt; $calw || $width &lt; $calh || $heigth &lt; $calh || $heigth &gt; $calh)
          {
          // here i save the resized image into the variable $newimg
  
          imagecopyresized($newimg, $img, 0,0,0,0, $calw, $calh, $width, $heigth);
          } else {
          $newimg = $img;
          }
          $tempimg = null;
          // a nested loop to automatically cut the image into pieces
  
          for($w = 0; $w &lt; $calw; $w+134){
              for($h = 0; $h &lt; $calh; $h+122){
                  // taking a piece of the image and save it into $tempimg
  
                  imagecopy($tempimg, $newimg, 0, 0, $w, $h, 134, 122);
  
                  // showing the image on screen
                  echo '&lt;div class="blokken" style="margin: 1px;"&gt;';
                  imagejpeg($tempimg);             
                  echo '&lt;/div&gt;';
              }
          }
      }
  }
  </code></pre>
  
  <p>what I am trying to do is:</p>
  
  <ol>
  <li>load in the image and resize it to the right size.</li>
  <li>cut it in pieces</li>
  <li>show it piece by piece with a little bit of space between them (i do that in a .css file hence the div tag)</li>
  </ol>
  
  <p>these are the errors that i get:</p>
  
  <pre><code>Warning: imagecopyresized(): supplied argument is not a valid Image resource in root\ons.php on line 52
  
  Warning: imagecopy(): supplied argument is not a valid Image resource in root\ons.php on line 63
  
  Warning: imagejpeg(): supplied argument is not a valid Image resource in root\ons.php on line 67
  
  Warning: imagecopy(): supplied argument is not a valid Image resource in root\ons.php on line 63
  </code></pre>
  
  <hr>
  
  <p>I thought that these functions might want a path to the image so I have also tried to make the image that was resized and the ones that were cut to save in this map .\image\ons\Ons-foto\ but that didn't work either. it didn't save the images nor did it load them back in to display them on the screen.</p>
  
  <p>What it also could be is that imagecreatefromjpeg() doesn't output what I think it outputs and saves in <code>$img</code> but <code>fopen()</code> didn't work either and gave the same error so I cant figure it out</p>
  
  <p>Could someone take a look at this and tell me why it doesn't work?
  to those who do, thank you</p>