Autor Zpráva
JoK1955
Profil *
Zdravím všechny. Mám script na upload a úpravu obrázků. Po uploadu vytvoří barevný a čb náhled. Na local normálně funguje, ale na hostingu nenajde fci imagefilter()
Fatal error: Call to undefined function imagefilter() in /var/www/imao/nasenoviny.net/home/admin/upfoto/fcefoto.php on line 173
Koukal jsem naverze ph. Na hostigu je 5.2.10-2.2, na locale mám 5.3.10-lubuntu3.6.
Script je zde:
    function _ImageToGray($original_file, $destination_file=NULL){
// --- prevod na skalu sedi
//    header("content-type: image/jpeg");
    $JpgImg = imagecreatefromjpeg($original_file);
    imagefilter($JpgImg,IMG_FILTER_GRAYSCALE);
    imagejpeg($JpgImg, $destination_file);
    imagedestroy($JpgImg);
Můžete mi někdo poradit, pls? JoK
Joker
Profil
JoK1955:
Funkce imagefilter vyžaduje GD knihovnu, viz manuál.
Zřejmě na hostingu není (to jde kdyžtak zjistit ve výpisu phpinfo, asi nejsnazší je hledat přítomnost sekce „gd“ ve výpisu), bude nutné řešit s podporou hostingu.
JoK1955
Profil *
[#2] Joker
Ale jo, je tam... Tady je výpis z phpinfo()
gd
GD Support     enabled
GD Version     2.0 or higher
FreeType Support     enabled
FreeType Linkage     with freetype
FreeType Version     2.3.9
T1Lib Support     enabled
GIF Read Support     enabled
GIF Create Support     enabled
JPG Support     enabled
PNG Support     enabled
WBMP Support     enabled 

Výpis phpinfo() je
www.nasenoviny.net/phpinfo.php


Dovětek
Předchozí kroky, tj. upload, zmenšení na 700px, vytvoření barevného náhledu se provedou!
peta
Profil
A verze php? V manuale je php 5. A jo, uz vidim, verze 5.2.10. V mojem php infu na localhost je treba tohle
PHP Version 5.3.5
GD Support     enabled
GD Version     bundled (2.0.34 compatible)
FreeType Support     enabled
FreeType Linkage     with freetype
FreeType Version     2.4.3
GIF Read Support     enabled
GIF Create Support     enabled
JPEG Support     enabled
libJPEG Version     6b
PNG Support     enabled
libPNG Version     1.2.44
WBMP Support     enabled
XBM Support     enabled
A mi to funguje.
JoK1955
Profil *
peta:

No mně na lokále také - viz výše
DJ Miky
Profil
Pravděpodobně jde o problém starší GD knihovny v Debianu nebo Ubuntu – viz http://www.agilepman.com/2010/07/fatal-error-call-to-undefined-function-imagefilter/. Pokud jseš na sdíleném hostingu, musíš se jedině obrátit na podporu, zda s tím nemůže něco udělat.
JoK1955
Profil *
DJ Miky:
Díky. Zkusil jsem

if (function_exists('imagefilter')) {
a vážně není. Napíšu hostingu.
JoK1955
Profil *
Tak mi hosting potvrdil, že imagefilter() v knihovně není a poradil mi
at zkusi pouzit jinou fci treba imagick
(http://cz2.php.net/manual/en/book.imagick.php)" 

ale ať koukám jak koukám, převod z color na grayscale nenacházím... Máte někdo zkušenosti?
peta
Profil
http://php.net/manual/en/function.imagefilter.php
Example #4 imagefilter() negate example
<?php
// Define our negate function so its portable for 
// php versions without imagefilter()
function negate($im)
{
    if(function_exists('imagefilter'))
    {
        return imagefilter($im, IMG_FILTER_NEGATE);
    }

    for($x = 0; $x < imagesx($im); ++$x)
    {
        for($y = 0; $y < imagesy($im); ++$y)
        {
            $index = imagecolorat($im, $x, $y);
            $rgb = imagecolorsforindex($index);
            $color = imagecolorallocate($im, 255 - $rgb['red'], 255 - $rgb['green'], 255 - $rgb['blue']);

            imagesetpixel($im, $x, $y, $color);
        }
    }

    return(true);
}

$im = imagecreatefromjpeg('kalle.jpg');

if($im && negate($im))
{
    echo 'Image successfully converted to negative colors.';

    imagejpeg($im, 'kalle.jpg', 100);
    imagedestroy($im);
}
else
{
    echo 'Converting to negative colors failed.';
}
?>
Jen teda pro grayscale bys musel googlovat nebo vedet, jak se to pocita
  for ($x = imagesx($im); $x--;) {
        for ($y = imagesy($im); $y--;) {
            $rgb = imagecolorat($im, $x, $y);
            $r = ($rgb >> 16) & 0xFF;
            $g = ($rgb >> 8 ) & 0xFF;
            $b = $rgb & 0xFF;
            $gray = ($r + $g + $b) / 3;
            if ($gray < 0xFF) {

                imagesetpixel($im, $x, $y, 0xFFFFFF);
            }else
                imagesetpixel($im, $x, $y, 0x000000);
        }
    }
$gray = ($r + $g + $b) / 3;
druha moznost je treba
$gray = 0.299*$r + 0.587*$g + 0.114*$b
JoK1955
Profil *
peta:
Díky za návod, ale...
z tohoto obrázku http://www.nasenoviny.net/fanhusk.jpg
to udělá toto http://www.nasenoviny.net/jm.jpg
peta
Profil
Ono to totiz dela tahle podminka, protoze autor chtel pouze cerny a bily, ne sede odstiny :) Priste ti zkusim dat link na forum, kde sem to nagoogloval.
            if ($gray < 0xFF) {
 
                imagesetpixel($im, $x, $y, 0xFFFFFF);
            }else
                imagesetpixel($im, $x, $y, 0x000000);
Kdezto ty potrebujes vytobit misto 0xFFFFFF nebo 0x000000 (0xRRGGBB) cislo 0x$gray$gray$gray.
JoK1955
Profil *
Tak jsem nasel tenhle script a vypadá, že funguje
    function _ImageToGray($original_file, $destination_file=NULL){
// --- prevod na skalu sedi
/* puvodni - nefunguje na hostingu, neni tam imagefilter v GD 28.6.2013 

//    header("content-type: image/jpeg");
    $JpgImg = imagecreatefromjpeg($original_file);
    imagefilter($JpgImg,IMG_FILTER_GRAYSCALE);
    imagejpeg($JpgImg, $destination_file);
    imagedestroy($JpgImg);
*/
// This sets it to a .jpg, but you can change this to png or gif if that is what you are working with
// header('Content-type: image/jpeg'); 
 // Get the dimensions
 list($width, $height) = getimagesize($original_file); 
 // Define our source image 
 $source = imagecreatefromjpeg($original_file); 
 // Creating the Canvas 
 $bwimage= imagecreate($width, $height); 
 //Creates the 256 color palette
 for ($c=0;$c<256;$c++) 
 {
 $palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);
 }
//Reads the origonal colors pixel by pixel 
 for ($y=0;$y<$height;$y++) 
 {
 for ($x=0;$x<$width;$x++) 
     {
 $rgb = imagecolorat($source,$x,$y);
 $r = ($rgb >> 16) & 0xFF;
 $g = ($rgb >> 8) & 0xFF;
 $b = $rgb & 0xFF;
//This is where we actually use yiq to modify our rbg values, and then convert them to our grayscale palette
 $gs = yiq($r,$g,$b);
 imagesetpixel($bwimage,$x,$y,$palette[$gs]);
 }
 } 
// Outputs a jpg image, but you can change this to png or gif if that is what you are working with
// imagejpeg($bwimage);
    imagejpeg($bwimage, $destination_file);
    imagedestroy($bwimage);
}

 //Creates yiq function
 function yiq($r,$g,$b) 
 {
 return (($r*0.299)+($g*0.587)+($b*0.114));
 } 

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0