Jump to content
php.lv forumi

Kāpēc imagepng taisa tukšu bildi?


Bunkertor 7

Recommended Posts

Sveiki,

 

Reku īss kodiņš kas samazina .PNG failu. Beigās thumb.png bilde tiešām tiek saglabāta uz servera, bet kad viņu attaisu vaļā, tad tā ir balta. Visa oriģinālās bildes informācija ir kaut kur pazudusi. Kāpēc?

 

<?php
$url = "path/to/large/image.png";
$image = imagecreatefrompng($url);
$result = imagecreate(148,111);

$fg = imagecolorallocate($result,255,255,255);
imagefilledrectangle($result,0,0,148,111,$fg);

$w = imagesx($image);
$h = imagesy($image);
$wscale = 148 / $w;
$hscale = 111 / $h;

if ($wscale < $hscale) {
$xresult = 148;
$yresult = $h * $wscale;
$xoffset = 0;
$yoffset = (111 - $yresult)/2;
} else {
$yresult = 111;
$xresult = $w * $hscale;
$xoffset = (148 - $xresult) / 2;
$yoffset = 0;
}

ImageCopyresized($result,$image,$xoffset,$yoffset,0,0,$xresult,$yresult,$w,$h);
imagepng($result, "thumb.png");
imagedestroy($result);
?>

Link to comment
Share on other sites

Paldies. Ja taisa uz $image tad vispār nekas nenotiek. Palaižu skriptu, skatos serverā, bet thumb.png neeksistē. Nekādu erroru nerāda, vienkārši bildi neuztaisa. Drošības pēc pārbaudīju vai $url ir pareizs. Tad jau iznāk, ka kļūda ir otrajā rindiņā, citādi kāpēc $image ir tukšs?

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...