Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Słaba jakość miniaturek.
dtrevo
post 23.02.2009, 16:53:52
Post #1





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 5.12.2008

Ostrzeżenie: (0%)
-----


Miniaturki wygladają strasznie

http://www.galeriasempy.yoyo.pl/galerie/naklo/

oto źródło

Robiący miniaturki:
CODE

<?php


session_start();


function linkuj($sciezka, $nazwa){
?>
<html>
<head></head>
<body>
<a href="<?php echo $sciezka; ?> "/><?php echo $nazwa; ?> </a>
</body>
</html>
<?php
}



$_SESSION['kat'] = $_POST['C2'];

$zmienna = $_POST['C2'];



$fol = "galerie/".$_SESSION['kat']; // folder ze zdjęciami
$folder = "galerie/";
$prfx = "min_"; // prefix poprzedzający nazwy miniaturek
$i = 0;


// chmod($fol, 0777);
$naz = array();
$dane = @file($fol."/dane.txt");
if(is_array($dane)) foreach($dane as $v) {
$t = explode("|", $v);
$naz[] = $t[0];
}

$uchwyt = opendir($fol);
while(false !== ($plik = readdir($uchwyt)))
if(is_file($fol."/".$plik) &&
(!is_file($fol."/".$prfx.$plik) || !in_array($plik, $naz)) &&
substr($plik, 0, strlen($prfx)) != $prfx &&
ereg("^.+\.jpe?g$", $plik) || ereg("^.+\.JPE?G$", $plik)) {
$org = imagecreatefromjpeg($fol."/".$plik);
$s_org = imagesx($org);
$w_org = imagesy($org);
$s_min = 250;
if(($w_min = floor(($s_min * $w_org) / $s_org)) > 150) $w_min = 200;
$min = imagecreate($s_min, $w_min);
imagecopyresized($min, $org, 0, 0, 0, 0, $s_min, $w_min, $s_org, $w_org);
imagedestroy($org);
imagejpeg($min, $fol."/".$prfx.$plik, 100);
imagedestroy($min);
if(in_array($plik, $naz)) unset($dane[array_search($plik, $naz)]);
$dane[] = "$plik|$s_org|$w_org|$prfx$plik|$s_min|$w_min\n";
$i++;
}
closedir($uchwyt);


$fp = fopen($fol."/dane.txt", "x");
flock($fp, 2);
fputs($fp, str_replace("\r", "", join("", $dane)));
flock($fp, 2);
fclose($fp);




I Wyświetlający
CODE




<table align="center">

<tr><td valign="top"><?
$ile = 2; //ilość zdjęć w jednym wierszu tabeli
$fol = "galerie/".$_SESSION[\'kat\']; //folder ze zdjęciami
$i = 1;
$dane = @file("dane.txt");
if(is_array($dane))
foreach($dane as $v) {
$d = explode("|", chop($v));
echo "<a href=\"$d[0]\" rel=\"lytebox[vacation]\" title=\"Ouch rulez\">".
"<img src=\"$d[3]\" width=\"$d[4]\" height=\"$d[5]\"></a>".
($i == $ile ? "</td></tr><tr><td valign=\"top\">" : "</td><td valign=\"top\">")."\n";
$i < $ile ? $i++ : $i = 1;
}

?></td></tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="760">
<tr>
<td>
<center><a href="http://www.studiotg.com"><img src="http://www.sempa.pl/galeria/grafika/logo1.gif" border="0"></a><br><b><a href="http://www.sempa.pl/index.php?id1=stopka&id2=stopka">Autorzy</a><br><br></center> </td>
</tr>
</table>


</td>
</tr>
</table>
</center>






Go to the top of the page
+Quote Post
mike
post 23.02.2009, 16:57:21
Post #2





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Zamień imagecopyresized() na imagecopyresampled()
Go to the top of the page
+Quote Post
dtrevo
post 23.02.2009, 17:08:38
Post #3





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 5.12.2008

Ostrzeżenie: (0%)
-----


nic nie dało
Go to the top of the page
+Quote Post
batman
post 24.02.2009, 08:41:38
Post #4





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




1. Jeśli tworzysz miniaturkę o niewielkich rozmiarach (np 30x30 px) to nie uzyskasz wysokiej jakości zdjęcia.
2. Usuń width i height ze znacznika img.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
dtrevo
post 24.02.2009, 09:15:58
Post #5





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 5.12.2008

Ostrzeżenie: (0%)
-----


znaczniki usunięte, ale problem tkwi w samym zmniejszaniu zdjecia, bo zdjecia zmniejszając o takich wymiarach co mam w skrypcie, są normalne. A zdjecia nie są małe 250x200
Go to the top of the page
+Quote Post
batman
post 24.02.2009, 09:35:33
Post #6





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




Jeśli to co napisał ~mike oraz usunięcie width i height nie pomogło, to na chwilę obecną nie wiem co może być przyczyną problemów. Jak znajdę chwilę, to dokładniej przyjrzę się skryptowi.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
sowiq
post 24.02.2009, 09:45:49
Post #7





Grupa: Zarejestrowani
Postów: 1 890
Pomógł: 339
Dołączył: 14.12.2006
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Miałem kiedyś podobny problem i znalazłem w komentarzach na php.net taką funkcję:

  1. <?php
  2. function imagecopyresampledSMOOTH(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $mult=1.25){
  3.    // don't use a $mult that's too close to an int or this function won't make much of a difference
  4.  
  5.    $tgt_w = round($src_w * $mult);
  6.    $tgt_h = round($src_h * $mult);
  7.  
  8.    // using $mult <= 1 will make the current step w/h smaller (or the same), don't allow this, always resize by at least 1 pixel larger
  9.    if($tgt_w <= $src_w){ $tgt_w += 1; }
  10.    if($tgt_h <= $src_h){ $tgt_h += 1; }
  11.  
  12.    // if the current step w/h is larger than the final height, adjust it back to the final size
  13.    // this check also makes it so that if we are doing a resize to smaller image, it happens in one step (since that's already smooth)
  14.    if($tgt_w > $dst_w){ $tgt_w = $dst_w; }
  15.    if($tgt_h > $dst_h){ $tgt_h = $dst_h; }
  16.  
  17.    $tmpImg = imagecreatetruecolor($tgt_w, $tgt_h);
  18.  
  19.    imagecopyresampled($tmpImg, $src_img, 0, 0, $src_x, $src_y, $tgt_w, $tgt_h, $src_w, $src_h);
  20.    imagecopy($dst_img, $tmpImg, $dst_x, $dst_y, 0, 0, $tgt_w, $tgt_h);
  21.    imagedestroy($tmpImg);
  22.  
  23.    // as long as the final w/h has not been reached, reep on resizing
  24.    if($tgt_w < $dst_w OR $tgt_h < $dst_h){
  25.        imagecopyresampledSMOOTH($dst_img, $dst_img, $dst_x, $dst_y, $dst_x, $dst_y, $dst_w, $dst_h, $tgt_w, $tgt_h, $mult);
  26.    }
  27. }
  28. ?>


Wywołanie identyczne jak dla imagecopyresampled(). Jakość jest zdecydowanie lepsza. Ale to subiektywna ocena smile.gif
Go to the top of the page
+Quote Post
l0ud
post 24.02.2009, 10:03:06
Post #8





Grupa: Zarejestrowani
Postów: 1 387
Pomógł: 273
Dołączył: 18.02.2008

Ostrzeżenie: (0%)
-----


Zamiast imagecopyresized - imagecopyresampled (jak napisali poprzednicy), poza tym zamiast imagecreate daj imagecreatetruecolor . U mnie druga operacja pomagała na spaprane kolory.


--------------------
XMPP: l0ud@chrome.pl
Go to the top of the page
+Quote Post
dtrevo
post 24.02.2009, 15:43:38
Post #9





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 5.12.2008

Ostrzeżenie: (0%)
-----


Cytat(l0ud @ 24.02.2009, 10:03:06 ) *
Zamiast imagecopyresized - imagecopyresampled (jak napisali poprzednicy), poza tym zamiast imagecreate daj imagecreatetruecolor . U mnie druga operacja pomagała na spaprane kolory.


ta pomogło, dzięki wszystkim
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.06.2025 - 15:58