Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP to create image sprite
    primarykey
    data
    text
    <p>I have a folder with 5 images that I would like to compile through PHP into a vertical image sprite. I've looped through all the items getting the data and saved it into an array:</p> <pre><code>Array ( [0] =&gt; Array ( [location] =&gt; uploads/test1/android.png [height] =&gt; 175 [width] =&gt; 175 [vertical] =&gt; 0 ) [1] =&gt; Array ( [location] =&gt; uploads/test1/autocad.png [height] =&gt; 225 [width] =&gt; 225 [vertical] =&gt; 175 ) [2] =&gt; Array ( [location] =&gt; uploads/test1/betting.png [height] =&gt; 512 [width] =&gt; 512 [vertical] =&gt; 400 ) [3] =&gt; Array ( [location] =&gt; uploads/test1/calculator.png [height] =&gt; 200 [width] =&gt; 200 [vertical] =&gt; 912 ) [4] =&gt; Array ( [location] =&gt; uploads/test1/ccleaner.png [height] =&gt; 256 [width] =&gt; 256 [vertical] =&gt; 1112 ) </code></pre> <p>)</p> <p>With vertical being the starting y coordinate for that image. Here's my current PHP:</p> <pre><code>$background = imagecreatetruecolor($horizontal, $vertical); $newimg = "sprite.jpg"; foreach($images as $i) { $tmp = imagecreatefromjpeg($i['location']); imagecopy($background, $tmp, 0, $i['vertical'], 0, 0, $i['width'], $i['height']); imagedestroy($tmp); } imagejpeg($background, $newimg); </code></pre> <p>$images is the array above. When I'm creating the array I calculate the horizontal and vertical variables (I've verified they are correct). I've tried a few things with the PHP and at one point managed to create a black image of the correct size (512x1368), but that's about as close as I've come. Any thoughts why this isn't working?</p> <hr> <p>Here is the updated code:</p> <pre><code>$background = imagecreatetruecolor($horizontal, $vertical); $newimg = "sprite.png"; foreach($images as $i) { $tmp = imagecreatefrompng($i['location']); imagecopy($background, $tmp, 0, $i['vertical'], 0, 0, $i['width'], $i['height']); imagedestroy($tmp); } imagepng($background, $newimg); </code></pre> <p>I've even tried commenting out the "imagedestroy" to see if that was the culprit. The code does not generate anything. Zero. Folder and image permissions are all 777. At this point I'm not real sure even which direction to try next. Any thoughts?</p> <hr> <p>Also tried "imagecreatefromstring", which also yielded no result (literally no file is being created).</p> <pre><code>$frame = imagecreatefromstring(file_get_contents($i['location'])); imagecopy($background, $frame, 0, $i['vertical'], 0, 0, $i['width'], $i['height']); imagedestroy($frame); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload