Convert to jpg on upload

Hi all,

I hate asking such a vague question but I’m really stuck. I did not build this site and am struggling to figure it out.

I have a page with thumbnails you can click to spring a lightbox which is capable of having a gif animate within it. (That first one pink ad should animate when you lightbox it)

I have another page that uploads the animated gif but it will not allow the animation to play. (The loaded orange ad “3 new…” should be animating)

I cannot figure out what the issue with that second page is. I just want the animations on the gif to play.
Any feedback is greatly appreciated!

Hi,

I’m not sure if this helps much, but if you include the image in the page without piping it through the sample.php script, then it works as expected.
Ergo, something in this script is causing it to break.

Can you post the contents of sample.php?

Pullo, thanks a ton for looking at it. I’m realizing looking back at my post how bad it was. I started posted thinking it was one thing, then switched my thinking mid-post. A bit cornfusing, but you get it.

Anyway, here is the code:

<?php
//$path = "http://images.templatemonster.com/screenshots/".$_GET["nm"]; //---Sample String for other's site data


$path=$_GET["nm"];


$string = $_GET['text'];
$jpeg = fopen($path,"r");
while (!feof($jpeg)) {
  $data .= fread($jpeg, 8192);
}

$mwidth=$_GET["mwidth"];
$mheight=$_GET["mheight"];

define(MAX_WIDTH, $mwidth);
define(MAX_HEIGHT, $mheight);

$img = null;

$img = @imagecreatefromstring($data);

if ($img) {

    # Get image size and scale ratio
    $width = imagesx($img);
    $height = imagesy($img);
    $scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);

    # If the image is larger than the max shrink it
    if ($scale < 1) {
        $new_width = floor($scale*$width);
        $new_height = floor($scale*$height);

        # Create a new temporary image
        		
		$tmp_img = imagecreatetruecolor($new_width, $new_height);

		$bgColor = imagecolorallocate($tmp_img, 255,25,255);
		imagefill($tmp_img , 0,0 , $bgColor);

        # Copy and resize old image into new image
        imagecopyresampled($tmp_img, $img, 0, 0, 0, 0,
                         $new_width, $new_height, $width, $height);
				
        imagedestroy($img);
        $img = $tmp_img;
    }
}

# Create error image if necessary
if (!$img) {
    $img = imagecreate(MAX_WIDTH, MAX_HEIGHT);
    imagecolorallocate($img,0,0,0);
    $c = imagecolorallocate($img,70,70,70);
    imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2);
    imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);
}

# Display the image
header( "Content-type: image/jpeg");
$orange = imagecolorallocate($img, 220, 210, 60);
$px    = (imagesx($img) - 7.5 * strlen($string)) / 2;
imagestring($img, 3, $px, 9, $string, $orange);
imagejpeg($img);
imagedestroy($img);
imagedestroy($tmp_img);
?>

No problem :slight_smile:

What happens if you change:

header( "Content-type: image/jpeg"); 

to:

header('Content-Type: image/gif');

at the end of the file?

I was wondering the same thing but it seemed to have no affect.

I made this change as well

// imagejpeg($img);
imagegif($img);

i deleted the gif and uploaded it again in the admin panel.
still does not animate.

Shame!

I’v ejust been doing some Googling and it seems that manipulating gifs in this way, does tend to destroy the animation.

So, let’s come at it from a different angle.
What do you want your PHP script to do?

yeah, i found the same thing just now googling around. i downsized the animation in fireworks so it still works, then uploaded it but it still was not animating.

My goals is to have that page function just like it is.
AND
have the gifs animate.

obviously something has to change with the page to get the animation but hopefully that change will only be in the code/scripting. if i have to have the page a bit different, then so be it.

actually the ideal would be what i just wrote AND be able to play videos too. :slight_smile:
but that might be a second discussion.

Yeah, but you’re piping the images through the sample.php script before displaying them on your page.
What should sample,php actually do?
Should it check the size of the images and resize them if necessary?

Yup :slight_smile:
One thing at a time.