开发者

php says php made png is invalid

开发者 https://www.devze.com 2023-01-24 15:50 出处:网络
So I have a function that turns a jpeg into a png image resizes it then saves it.Then a bit later i come back to it and use the image in a rotate function.I keep getting errors though.It says uploads/

So I have a function that turns a jpeg into a png image resizes it then saves it. Then a bit later i come back to it and use the image in a rotate function. I keep getting errors though. It says uploads/image.png isnt a valid PNG file. The weird thing is that it only does then on php edited png files. If i delete image.png and download a png from the internet name is image.png is works fine as long as i dont run it through the first resize script.

function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
    $imagecreated = imagecreatefromjpeg($filename);
    $this->image = $imagecreated;
    $extention = pathinfo($filename, PATHINFO_EXTENSION);
    $basename = basename($filename, ".".$extention);
    $newname = "uploads/".$basename;
    imagepng($imagecreated, $newname.".png", 0);
// ....???

function resize($width,$height) {
    $new_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height,
        $this->getWidth(), $this->getHeight());
    $this->image = $new_image;
}

Then i save the file with just a simple

imagepng(etc etc);

I go to the uploads folder and it looks fine. its resized and everything. I also noticed photoshop wont open the edited png either.

Also the line of code that produces the error is here..

$image = imagecreatefrompng('uploads/image.png'); 开发者_如何学Python


Possible fix is to add a NULL for your filters parameter (the last parameter in imagepng)

ie.

imagepng($image,$file_location,0,NULL);

I can't say this should be needed, but I read a similar case where someone noted they had to do this, may be dependant on the version of libpng or gd lib.

0

精彩评论

暂无评论...
验证码 换一张
取 消