0

I have an sprite with a few icons, about 30. I use them by setting the background position of one specific icon. But now, I want to use one icon like a image, to put them for example, in the facebook og:img metatag..

So, how can I generate the icon, by php and GD?

mydomain.com/generate_icon.php?icon_id=5

Is there any other way to do this without GD?

6
  • Why wouldn't you want to use GD? There is also ImageMagick. Commented Oct 28, 2012 at 22:26
  • 1
    I do not understand what you are asking. What do you want to generate from where? Commented Oct 28, 2012 at 22:26
  • 1
    @Pekka, My read is that he has a large image with 30 sprites within its area, and he wants to extract one and output as a single image. Commented Oct 28, 2012 at 22:26
  • @Brad that sounds like a good interpretation, yeah. mauriblint - any specific reason why you can't use GD? Commented Oct 28, 2012 at 22:27
  • exactly! I've a big image, this: nopagocable.com.ar/images/sprites_icon.png That I gen with Photoshop.. , my questions is, how can i do this with GD or other method.. sorry for my English!! :) Commented Oct 28, 2012 at 22:32

2 Answers 2

2

how can i do this with GD or other method.. sorry for my English!! here is an example WITH GD

$no = isset($_GET['no']) ? $_GET['no'] : 0; <---- Image Number via GET
$img = "sprites.png";
list($h, $w) = getimagesize($img);
$size = ($h < $w) ? $h : $w;

$src = imagecreatefrompng($img);
$dest = imagecreatetruecolor($size, $size);

imagecopy($dest, $src, 0, 0, 0, ($size * $no), $size, $size);

// Output and free from memory
header('Content-Type: image/png');
imagegif($dest);

Usage image.php?no=5

Sign up to request clarification or add additional context in comments.

Comments

0

try that: http://phpthumb.sourceforge.net/ - many options and you can do it in a way you want: mydomain.com/generate_icon.php?icon_id=5 . An Example of cropping and filtering is looking like that: <img border="0" src="../phpThumb.php?src=images/loco.jpg&amp;w=300&amp;fltr[]=crop|50&amp;hash=6af23273fc8ec3513eca71d51b018f32" alt="">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.