Reputation: 18198
OK, let's say I have this image:
In my Java game, I use a cropping method which crops each monster of 32x32 pixels and thus puts in monster[0]
onwards. Anyways, in PHP, is there some way I can do this? Like crop an image and go from there?
Any help would be appreciated.
Upvotes: 0
Views: 76
Reputation: 341
Hi you can crop the image via imagecopyresampled the man page http://php.net/manual/de/function.imagecopyresampled.php You just have to set the correct offset.
if this should be displayed in a Browser you can do it even via CSS
.selector {
height: 32px;
width: 32px;
overflow: hidden;
display: inline-block;
background: url(theimage.gif) -32px 0px no-repeat;
}
Hope it helps
Upvotes: 1
Reputation: 2376
You can use imagecreatefromgif()
with PHP where you can create a new image on the fly by giving specific x and y positions. Rather than just me copy/pasting the code, here is the link to the documentation.
http://php.net/manual/en/function.imagecreatefromgif.php
You can also use different variations of imagecreatefromgif()
such as imagecreatefromjpeg()
or imagecreatefrompng()
etc
All are linked to on the PHP documentation page as well as more examples in the comments.
Upvotes: 1
Reputation: 23542
Don't crop it. You can use it as it is with CSS background-position. The the sive of a and move the background to the image you want. It is faster than loading every image on its own.
Upvotes: 0