Author Topic: PHP Imagick  (Read 887 times)

Offline Sim

  • Level 13
  • *
  • Posts: 104
  • Reputation: +1/-1
    • View Profile
    • Online RPG Creator
PHP Imagick
« on: February 10, 2011, 09:43:19 AM »
Code works fine with all file types except png's. When a png is uploaded, it creates ONE 75 MB core.##### file per png in my directory and stops executing... any ideas?

Code: [Select]
<?
if(isset($_POST['SubmitForm']))
{
//setup Imagick
    $IMG = new Imagick();
$IMG->setFormat("gif");

//loop through possible files
for($x=1; $x< ($_POST['hidden']+1); $x++)
{
if(!empty($_FILES['file' . $x]['tmp_name']))
{
//add image to frame
$frame = new Imagick($_FILES['file' . $x]['tmp_name']);     

$IMG->addImage($frame);
//100 = 1s
$IMG->setImageDelay($delay = 50);
}
}

//rand name just for testing purposes
$name = rand(1, 99999);
$IMG->writeImages("$name.gif", true); // combine all image into one single image
}
?>

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: PHP Imagick
« Reply #1 on: February 10, 2011, 11:26:05 AM »
Why are you setting the type as .gif and not .png for .png files?

Offline Sim

  • Level 13
  • *
  • Posts: 104
  • Reputation: +1/-1
    • View Profile
    • Online RPG Creator
Re: PHP Imagick
« Reply #2 on: February 11, 2011, 02:03:26 AM »
because its going to produce an animated gif?

Offline andrewjbaker

  • Level 17
  • *
  • Posts: 154
  • Reputation: +2/-0
    • View Profile
    • Fleeting Fantasy
Re: PHP Imagick
« Reply #3 on: February 11, 2011, 03:44:09 AM »
Ah... so the idea is that someone uploads a series of .png files and they're used to generate an animated .gif? Or do I misunderstand?
Currently working on an HTML5 canvas 2.5D landscape renderer and a PBBG that uses it (http://fleetingfantasy.com/). The development blog's at http://fleetingfantasy.wordpress.com/.
What are BBGameZone members working on? See the game list.
irc.freenode.net, #bbg

Offline Sim

  • Level 13
  • *
  • Posts: 104
  • Reputation: +1/-1
    • View Profile
    • Online RPG Creator
Re: PHP Imagick
« Reply #4 on: February 11, 2011, 04:21:27 AM »
They upload a series of any images and it creates an animated gif. ;]

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: PHP Imagick
« Reply #5 on: February 11, 2011, 06:28:53 AM »
But isn't GIF 256 colour only format? You would need to use some advanced pallete selection algorithm (assuming the pictures are random colour non unified palette). I'm not sure software is capable of such things, it would rather require some skilled artist...

Offline Sim

  • Level 13
  • *
  • Posts: 104
  • Reputation: +1/-1
    • View Profile
    • Online RPG Creator
Re: PHP Imagick
« Reply #6 on: February 11, 2011, 07:03:07 AM »
But isn't GIF 256 colour only format? You would need to use some advanced pallete selection algorithm (assuming the pictures are random colour non unified palette). I'm not sure software is capable of such things, it would rather require some skilled artist...

I'm not sure. Maybe my best bet would be to just convert all png's to jpg's or gif's ;\

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: PHP Imagick
« Reply #7 on: February 11, 2011, 07:15:11 AM »
Ok, I can follow that....

But it seems like you would need to set your headers for this to display properly.  Again, what type of error is it throwing?

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: PHP Imagick
« Reply #8 on: February 11, 2011, 11:28:38 AM »
Quote
GIF creates a table of up to 256 colors from a pool of 16 million. If the image has fewer than 256 colors, GIF can render the image exactly. When the image contains many colors, software that creates the GIF uses any of several algorithms to approximate the colors in the image with the limited palette of 256 colors available. Better algorithms search the image to find an optimum set of 256 colors. Sometimes GIF uses the nearest color to represent each pixel, and sometimes it uses "error diffusion" to adjust the color of nearby pixels to correct for the error in each pixel.

GIF achieves compression in two ways. First, it reduces the number of colors of color-rich images, thereby reducing the number of bits needed per pixel, as just described. Second, it replaces commonly occurring patterns (especially large areas of uniform color) with a short abbreviation: instead of storing "white, white, white, white, white," it stores "5 white."

Thus, GIF is "lossless" only for images with 256 colors or less. For a rich, true color image, GIF may "lose" 99.998% of the colors.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal