Closed leikxile closed 10 years ago
I'll look at this later this evening.
The problem is that the Gif apparently exceeds the size restriction set by the $maxImageWidth and $maxImageHeight variables.
Resizing an animation is not that easy though.
Hi Grandt,
I tried using a smaller gif image http://www.afh.com/web/gif89a/sample2.gif But still the animation is gone this is because of the image conversion is to a png but i just made it a gif mimetype see code below:
if ($mime == "image/gif") { imagealphablending($image_p, false); imagesavealpha($image_p, true); imagealphablending($image_o, true); imagecopyresampled($image_p, $imageo, 0, 0, 0, 0, ($width$ratio), ($height_$ratio), $width, $height); ob_start(); imagepng($image_p, NULL, 9); $image = ob_get_contents(); ob_end_clean();
$ext = "gif"; }
this function is for png, I don't know what to do if it is a gif image. I do remember gifs are working in the earlier versions of your epub class so I tried copying the function in the image conversion to the present epub class but this function now converts it to a jpeg file.
On Sun, Jan 12, 2014 at 3:06 AM, Asbjørn Grandt notifications@github.comwrote:
The problem is that the Gif apparently exceeds the size restriction set by the $maxImageWidth and $maxImageHeight variables.
Resizing an animation is not that easy though.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32120057 .
Hi
I have a different solution, but I have to revert some code. I tried to convert/resize the animation, but with very bad results. But the new code correctly handles non animated gifs now. This is the section, without animation support.
if ($ratio < 1 || empty($mime)) {
if ($mime == "image/png" || ($this->isGifImagesEnabled
=== FALSE && $mime == "image/gif")) { $image_o = imagecreatefromstring($image); $imagep = imagecreatetruecolor($width$ratio, $height_$ratio);
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagealphablending($image_o, true);
imagecopyresampled($image_p, $image_o, 0, 0, 0, 0,
($width$ratio), ($height$ratio), $width, $height); ob_start(); imagepng($image_p, NULL, 9); $image = ob_get_contents(); ob_end_clean();
imagedestroy($image_o);
imagedestroy($image_p);
$ext = "png";
} else if ($this->isGifImagesEnabled !== FALSE && $mime
== "image/gif") { $image_o = imagecreatefromstring($image); $imagep = imagecreatetruecolor($width$ratio, $height_$ratio);
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagealphablending($image_o, true);
imagecopyresampled($image_p, $image_o, 0, 0, 0, 0,
($width$ratio), ($height$ratio), $width, $height); ob_start(); imagegif($image_p, NULL); $image = ob_get_contents(); ob_end_clean();
imagedestroy($image_o);
imagedestroy($image_p);
$ext = "gif";
} else {
$image_o = imagecreatefromstring($image);
$image_p = imagecreatetruecolor($width*$ratio,
$height*$ratio);
imagecopyresampled($image_p, $image_o, 0, 0, 0, 0,
($width$ratio), ($height$ratio), $width, $height); ob_start(); imagejpeg($image_p, NULL, 80); $image = ob_get_contents(); ob_end_clean();
imagedestroy($image_o);
imagedestroy($image_p);
$mime = "image/jpeg";
$ext = "jpg";
}
The initial check for if the gifs were to be enabled, was misplaced. Now, if they are not enabled, they'll be changed to a png, else resized as a gif. The corrections you made only needed the change from imagepng to imagegif, and the extra check.
On 13-01-2014 08:44, leikxile wrote:
Hi Grandt,
I tried using a smaller gif image http://www.afh.com/web/gif89a/sample2.gif But still the animation is gone this is because of the image conversion is to a png but i just made it a gif mimetype see code below:
if ($mime == "image/gif") { imagealphablending($image_p, false); imagesavealpha($image_p, true); imagealphablending($image_o, true); imagecopyresampled($image_p, $imageo, 0, 0, 0, 0, ($width$ratio), ($height_$ratio), $width, $height); ob_start(); imagepng($image_p, NULL, 9); $image = ob_get_contents(); ob_end_clean();
$ext = "gif"; }
this function is for png, I don't know what to do if it is a gif image. I do remember gifs are working in the earlier versions of your epub class so I tried copying the function in the image conversion to the present epub class but this function now converts it to a jpeg file.
On Sun, Jan 12, 2014 at 3:06 AM, Asbjørn Grandt notifications@github.comwrote:
The problem is that the Gif apparently exceeds the size restriction set by the $maxImageWidth and $maxImageHeight variables.
Resizing an animation is not that easy though.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32120057 .
— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/20#issuecomment-32149982.
Based on my research recreating gif images will remove the animations hmm... will try to research on this more. btw thanks for this fix.
On Mon, Jan 13, 2014 at 12:08 AM, Asbjørn Grandt notifications@github.comwrote:
Hi
I have a different solution, but I have to revert some code. I tried to convert/resize the animation, but with very bad results. But the new code correctly handles non animated gifs now. This is the section, without animation support.
if ($ratio < 1 || empty($mime)) { if ($mime == "image/png" || ($this->isGifImagesEnabled === FALSE && $mime == "image/gif")) { $image_o = imagecreatefromstring($image); $imagep = imagecreatetruecolor($width$ratio, $height_$ratio);
imagealphablending($image_p, false); imagesavealpha($image_p, true); imagealphablending($image_o, true);
imagecopyresampled($image_p, $imageo, 0, 0, 0, 0, ($width$ratio), ($height_$ratio), $width, $height); ob_start(); imagepng($image_p, NULL, 9); $image = ob_get_contents(); ob_end_clean();
imagedestroy($image_o); imagedestroy($image_p);
$ext = "png"; } else if ($this->isGifImagesEnabled !== FALSE && $mime == "image/gif") { $image_o = imagecreatefromstring($image); $imagep = imagecreatetruecolor($width$ratio, $height_$ratio);
imagealphablending($image_p, false); imagesavealpha($image_p, true); imagealphablending($image_o, true);
imagecopyresampled($image_p, $imageo, 0, 0, 0, 0, ($width$ratio), ($height_$ratio), $width, $height); ob_start(); imagegif($image_p, NULL); $image = ob_get_contents(); ob_end_clean();
imagedestroy($image_o); imagedestroy($image_p);
$ext = "gif"; } else {
$image_o = imagecreatefromstring($image); $imagep = imagecreatetruecolor($width$ratio, $height_$ratio);
imagecopyresampled($image_p, $imageo, 0, 0, 0, 0, ($width$ratio), ($height_$ratio), $width, $height); ob_start(); imagejpeg($image_p, NULL, 80); $image = ob_get_contents(); ob_end_clean();
imagedestroy($image_o); imagedestroy($image_p);
$mime = "image/jpeg"; $ext = "jpg"; }
The initial check for if the gifs were to be enabled, was misplaced. Now, if they are not enabled, they'll be changed to a png, else resized as a gif. The corrections you made only needed the change from imagepng to imagegif, and the extra check.
On 13-01-2014 08:44, leikxile wrote:
Hi Grandt,
I tried using a smaller gif image http://www.afh.com/web/gif89a/sample2.gif But still the animation is gone this is because of the image conversion is to a png but i just made it a gif mimetype see code below:
if ($mime == "image/gif") { imagealphablending($image_p, false); imagesavealpha($image_p, true); imagealphablending($image_o, true); imagecopyresampled($image_p, $imageo, 0, 0, 0, 0, ($width$ratio), ($height_$ratio), $width, $height); ob_start(); imagepng($image_p, NULL, 9); $image = ob_get_contents(); ob_end_clean();
$ext = "gif"; }
this function is for png, I don't know what to do if it is a gif image. I do remember gifs are working in the earlier versions of your epub class so I tried copying the function in the image conversion to the present epub class but this function now converts it to a jpeg file.
On Sun, Jan 12, 2014 at 3:06 AM, Asbjørn Grandt notifications@github.comwrote:
The problem is that the Gif apparently exceeds the size restriction set by the $maxImageWidth and $maxImageHeight variables.
Resizing an animation is not that easy though.
— Reply to this email directly or view it on GitHub<https://github.com/Grandt/PHPePub/issues/20#issuecomment-32120057
.
— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/20#issuecomment-32149982.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32150833 .
The problem with animated Gifs is that you have to decompose the animation, and then resize each frame individually, then recompose it again. Adding to the complexity is the "optimized" animated gifs, where a frame may not discard the previous, and just "paint" over part of it, in those you have to recalculate the offset as well when you recompose it.
Hmm.. sorry I do not have that kind of knowledge to do that lol, though if all else fails, can I just download the file if it is image using file_put_contents? so it will not recreate the gif file?
On Mon, Jan 13, 2014 at 10:02 PM, Asbjørn Grandt notifications@github.comwrote:
The problem with animated Gifs is that you have to decompose the animation, and then resize each frame individually, then recompose it again. Adding to the complexity is the "optimized" animated gifs, where a frame may not discard the previous, and just "paint" over part of it, in those you have to recalculate the offset as well when you recompose it.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32240904 .
I didn't know either, until Sunday :)
I'll have to think on this though, as while adding the file directly is possible, if the link in the HTML isn't relative, the image may not be reachable in the ePub.
But does it still enter the resize part of the code, when the gif is small enough?
What happens if you set $book->maxImageWidth and $book->maxImageHeight to something larger than the gif size? They defaults to 768 and 1024 respectively.
On 14-01-2014 07:40, leikxile wrote:
Hmm.. sorry I do not have that kind of knowledge to do that lol, though if all else fails, can I just download the file if it is image using file_put_contents? so it will not recreate the gif file?
On Mon, Jan 13, 2014 at 10:02 PM, Asbjørn Grandt notifications@github.comwrote:
The problem with animated Gifs is that you have to decompose the animation, and then resize each frame individually, then recompose it again. Adding to the complexity is the "optimized" animated gifs, where a frame may not discard the previous, and just "paint" over part of it, in those you have to recalculate the offset as well when you recompose it.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32240904 .
— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/20#issuecomment-32242112.
Adding an image link in an ePub is not advisable since the device may sometimes go offline right? So the class should download the file right into the book. This could be an exception for the gif files since they are very hard to recreate.
I tried an image with a resolution of 480x300 but it failed, tried increasing $book->maxImageWidth and $book->maxImageHeight also but no luck.
On Mon, Jan 13, 2014 at 10:50 PM, Asbjørn Grandt notifications@github.comwrote:
I didn't know either, until Sunday :)
I'll have to think on this though, as while adding the file directly is possible, if the link in the HTML isn't relative, the image may not be reachable in the ePub.
But does it still enter the resize part of the code, when the gif is small enough?
What happens if you set $book->maxImageWidth and $book->maxImageHeight to something larger than the gif size? They defaults to 768 and 1024 respectively.
On 14-01-2014 07:40, leikxile wrote:
Hmm.. sorry I do not have that kind of knowledge to do that lol, though if all else fails, can I just download the file if it is image using file_put_contents? so it will not recreate the gif file?
On Mon, Jan 13, 2014 at 10:02 PM, Asbjørn Grandt notifications@github.comwrote:
The problem with animated Gifs is that you have to decompose the animation, and then resize each frame individually, then recompose it again. Adding to the complexity is the "optimized" animated gifs, where a frame may not discard the previous, and just "paint" over part of it, in those you have to recalculate the offset as well when you recompose it.
— Reply to this email directly or view it on GitHub<https://github.com/Grandt/PHPePub/issues/20#issuecomment-32240904
.
— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/20#issuecomment-32242112.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32242464 .
I'll have to look into this, something else is wrong then. At that size the GIF should not even be attempted to be processed, it should just be added.
Alright, thank you moral support here :)
On Mon, Jan 13, 2014 at 11:15 PM, Asbjørn Grandt notifications@github.comwrote:
I'll have to look into this, something else is wrong then. At that size the GIF should not even be attempted to be processed, it should just be added.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32243325 .
Please note that some ePub readers will not play the animation. For instance Sony Reader for PC doesn't.
I'll look at it some more tonight, when I get back from work. Until then, have a look at the new 3.21 branch. It seems to work without trying to resize the animated gif.
Alright thank you!
On Mon, Jan 13, 2014 at 11:28 PM, Asbjørn Grandt notifications@github.comwrote:
I'll look at it some more tonight, when I get back from work. Until then, have a look at the new 3.21 branch. It seems to work without trying to resize the animated gif.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32243821 .
Forgot to say that the file is from an external source.
On Mon, Jan 13, 2014 at 11:31 PM, Kiel Lago kiellago@gmail.com wrote:
Alright thank you!
On Mon, Jan 13, 2014 at 11:28 PM, Asbjørn Grandt <notifications@github.com
wrote:
I'll look at it some more tonight, when I get back from work. Until then, have a look at the new 3.21 branch. It seems to work without trying to resize the animated gif.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32243821 .
Try to uncomment the echo just before the if ($ratio <1... line in 3.21. It will of course fail the script but i'd like to know whai it prints for the gif. Remember to enable error reporting as seen in the example scripts.
Here is the output
$source: http://localhost/public_html/includes/lib_uploader/uploads/2014-01-15/1/52d5d498298db/elem-52d5d503d2d91.gif $ratio.: 1 $mime..: image/gif $width.: 480 $height: 360
On Tue, Jan 14, 2014 at 12:15 AM, Asbjørn Grandt notifications@github.comwrote:
Try to uncomment the echo just before the if ($ratio <1... line in 3.21. It will of course fail the script but i'd like to know whai it prints for the gif. Remember to enable error reporting as seen in the example scripts.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32245819 .
Then it shouldn't even have entered that resizing code. The line
if ($ratio < 1 || empty($mime)) {
should stop it right there. If you unzip the epub file, and look at the gif there, is it still broken?
Yup that is what i've been thinking of.. I even tried to comment the resizing part. So it downloaded the file but the animation is gone. So this means that the problem is not in the resizing part anymore right?
On Tue, Jan 14, 2014 at 1:32 AM, Asbjørn Grandt notifications@github.comwrote:
Then it shouldn't even have entered that resizing code. The line
if ($ratio < 1 || empty($mime)) {
should stop it right there.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32249988 .
Is the gif file in the epub file itself changed? Rename the epub to .zip and unpack it, the file should be in OEBPS/images/localhost/public_html/includes/lib_uploader/uploads/2014-01-15/1/52d5d498298db/elem-52d5d503d2d91.gif
As I said, some readers don't play the animation.
Yup i've checked the file it is a gif image but tried opening it in photo viewer, the animation is gone, transparent yes, but is just a flat image.
On Tue, Jan 14, 2014 at 2:16 AM, Asbjørn Grandt notifications@github.comwrote:
Is the gif file in the epub file itself changed? Rename the epub to .zip and unpack it, the file should be in
OEBPS/images/localhost/public_html/includes/lib_uploader/uploads/2014-01-15/1/52d5d498298db/elem-52d5d503d2d91.gif
As I said, some readers don't play the animation.
— Reply to this email directly or view it on GitHubhttps://github.com/Grandt/PHPePub/issues/20#issuecomment-32252758 .
Hi
Can I get you to send me the generated ePub file (or just a simple test file containing that gif from the link you used, as well as the original gif?
Please use the address php@grandt.com
Cheers
Hi
EPub.Example3_2.php in the 3.21 branch loads the animated gif correctly.
issue has been fixed thank you!
Hi, I came across with the problem of gif images being a jpeg file. I've set isGifImagesEnabled to true. Still Gif images are becoming jpeg files so i've check the code and noticed that the
$mime
only has png and jpeg conditions so i added the gif condition. Please see code below, the problem is the animation is gone.`if ($mime == "image/png") { imagealphablending($image_p, false); imagesavealpha($image_p, true);
imagealphablending($image_o, true);