Foto upload vs kwaliteit
Voorbeeld mijn scriptje:
Voorbeeld Flickr:
Ik gebruik deze: thumbnail class en gebruik deze code om te uploaden:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
include('includes/classes/thumbnail.php');
$path = 'afbeeldingen/';
$image_width = 500;
$thumbnail_size = 100;
//-- form's been posted, size is bigger than 25kb, tmp file exists and it's a jpg, jpeg, png or gif file
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_FILES['userfile']['size'] > 25 && is_uploaded_file($_FILES['userfile']['tmp_name']) && (strtolower(substr($_FILES['userfile']['name'], -3)) == 'jpg' || strtolower(substr($_FILES['userfile']['name'], -4)) == 'jpeg' || strtolower(substr($_FILES['userfile']['name'], -3)) == 'png' || strtolower(substr($_FILES['userfile']['name'], -3)) == 'gif'))
{
$filename = date('Y-m-d') . '_' . $_SESSION['id'] . '_' . substr($_FILES['userfile']['name'], 0, 30);
//--- upload image naar $path
move_uploaded_file($_FILES['userfile']['tmp_name'], $path . $filename);
//--- resize to max width
$thumb=new thumbnail($path . $filename); // generate image_file, set filename to resize
//$thumb->size_width($thumbnail_size); // set width for thumbnail, or
//$thumb->size_height($thumbnail_size); // set height for thumbnail, or
$thumb->size_auto(500); // set the biggest width or height for thumbnail
$thumb->jpeg_quality(100);
$thumb->show(); // show your thumbnail
//$thumb->save("./huhu.jpg"); // save your thumbnail to file
}
else
{
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '" enctype="multipart/form-data">';
echo '<p>';
echo '<input type="file" name="userfile" value="" /><br />';
echo '<input type="submit" name="submit" value="Upload\'n!" />';
echo '</p>';
echo '</form>';
}
?>
include('includes/classes/thumbnail.php');
$path = 'afbeeldingen/';
$image_width = 500;
$thumbnail_size = 100;
//-- form's been posted, size is bigger than 25kb, tmp file exists and it's a jpg, jpeg, png or gif file
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_FILES['userfile']['size'] > 25 && is_uploaded_file($_FILES['userfile']['tmp_name']) && (strtolower(substr($_FILES['userfile']['name'], -3)) == 'jpg' || strtolower(substr($_FILES['userfile']['name'], -4)) == 'jpeg' || strtolower(substr($_FILES['userfile']['name'], -3)) == 'png' || strtolower(substr($_FILES['userfile']['name'], -3)) == 'gif'))
{
$filename = date('Y-m-d') . '_' . $_SESSION['id'] . '_' . substr($_FILES['userfile']['name'], 0, 30);
//--- upload image naar $path
move_uploaded_file($_FILES['userfile']['tmp_name'], $path . $filename);
//--- resize to max width
$thumb=new thumbnail($path . $filename); // generate image_file, set filename to resize
//$thumb->size_width($thumbnail_size); // set width for thumbnail, or
//$thumb->size_height($thumbnail_size); // set height for thumbnail, or
$thumb->size_auto(500); // set the biggest width or height for thumbnail
$thumb->jpeg_quality(100);
$thumb->show(); // show your thumbnail
//$thumb->save("./huhu.jpg"); // save your thumbnail to file
}
else
{
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '" enctype="multipart/form-data">';
echo '<p>';
echo '<input type="file" name="userfile" value="" /><br />';
echo '<input type="submit" name="submit" value="Upload\'n!" />';
echo '</p>';
echo '</form>';
}
?>
Doe ik iets verkeerd? Ik heb het ook met andere scriptjes geprobeerd, maar de kwaliteit blijft ook daar niet naar mijn standaarden :) :) Heeft iemand tips hoe dit wel aan te pakken? Want ik wil geen vervormde foto's op mijn website.
Gewijzigd op 01/01/1970 01:00:00 door Ronald
imagecopyresize gebruikt. Deze heb ik vervangen voor een ander functie:
En heb in de class nu dus staan:
Heb het antwoord gevonden. In de class wordt Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
function ImageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
/*
* Port to PHP by John Jensen July 10 2001 -- original code
* (in C, for the PHP GD Module) by [email protected]
*/
for ($i = 0; $i < 256; $i++)
{
// get pallete. Is this algoritm correct?
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $dst_h; $j++)
{
$sY = $j * $scaleY;
for ($i = $src_x; $i < $dst_w; $i++)
{
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY));
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = ImageColorClosest ($dst_img, $red, $green, $blue);
ImageSetPixel ($dst_img, $i + $dst_x, $j + $dst_y, $color);
}
}
}
?>
function ImageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
/*
* Port to PHP by John Jensen July 10 2001 -- original code
* (in C, for the PHP GD Module) by [email protected]
*/
for ($i = 0; $i < 256; $i++)
{
// get pallete. Is this algoritm correct?
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $dst_h; $j++)
{
$sY = $j * $scaleY;
for ($i = $src_x; $i < $dst_w; $i++)
{
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY));
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = ImageColorClosest ($dst_img, $red, $green, $blue);
ImageSetPixel ($dst_img, $i + $dst_x, $j + $dst_y, $color);
}
}
}
?>
En heb in de class nu dus staan:
# 11 March 2003
gebruik een recente, en vervang imagecopyresized door imagecopyresampled. Dat zorgt voor betere kwaliteit
ImageMagick sowieso betere resultaten gaf dan gd, misschien kan je daar naar kijken.
Volgens mij was het zo dat Tnx Karl, gebruk nu bovenstaande class en die werkt goed! :D