PHP GD ya haɓaka image Hoton ba za a iya nunawa ba saboda yana dauke da kurakurai a Firefox

PHP GD ya haɓaka image Hoton ba za a iya nunawa ba saboda yana dauke da kurakurai a Firefox

A lokacin da samar da hoto tare da PHP, misali ƙara wani alamar ruwa zuwa uwar garken adana da aka adana, ta amfani da lambar ƙasa, ko kuma irin wannan tare da JPEG maimakon PNG, hoto bazai haifar da komai ba kuma jefa kuskure, a bayyane akan Firefox, amma ba a kan Chrome.

Irin wannan lambar, duk da aiki a kan wasu sabobin, na iya aiki a kan wasu, wani lokaci don dalilai mara kyau. A cikin akwati, ya yi aiki sosai a gida, amma ya samar da kuskure a ƙasa a kan uwar garken intanit, ba a iya nuna hoton ba saboda yana dauke da kurakurai.

Tambaya na iya fitowa daga dalilai da yawa, ga wasu daga cikinsu:

An riga an saita fitarwa a baya.

Kuskuren kuskure daga tsarawar hoto.

An yi amfani da nau'in siffar ba daidai ba.

Ba a shigar da ɗakin hoton hoto ba.

$stamp = imagecreatefrompng('watermark.png');
if(!$im = imagecreatefrompng('image.png')) die('Error generating image');
$marge_right = $marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

$copyimage = imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

header('Content-type: image/png');
if(!imagepng($im)) die('Error generating image');
if(!imagedestroy($im)) die('Error generating image');
if(!imagedestroy($stamp)) die('Error generating image');

An riga an saita fitarwa a baya

Ko da ba da gangan ba, yana iya kasancewa misali misali wasu rubutun da suka gabata sun ƙunshi sarari a ƙarshen - don kauce wa wannan kuskure, tabbatar da cewa, kamar yadda PHP ya bada shawarar, ba don rufe rubutun tare da maɓallin ƙafa na PHP ba?>

Bayan haka, kafin yin amfani da aikin kaiwa, yi amfani da code na gaba don tabbatar da duk wanda ya sa aka fara yin saiti

foreach (getallheaders() as $name => $value) {
header_remove($name);
}

Har ila yau, wannan aikin don tabbatar da cewa babu wani kayan aiki da aka samar a gaban maɓallin kai da hoto

ob_end_clean();

Wannan ya warware matsalar a cikin akwati, kuma an nuna hoton a sake nunawa.

Kuskuren kuskure daga tsarawar hoto

Idan akwai kuskuren da aka jefa a lokacin tsarawar hoto, tabbatar da an saita PHP don nuna duk wani irin kurakurai, da kuma bincika rajistan ayyukan, domin ya iya yin amfani da shi da kuma warware shi.

Abubuwan da ke biyowa za su sa PHP ta ba da rahoton duk kurakurai a cikin log:

error_reporting(E_ALL);
ini_set('display_errors', '1');

Kuna iya gane cewa wasu kurakurai sun ruwaito, koda kuwa ba su bayyana a cikin html ba, saboda sabuntawar uwar garke.

An yi amfani da nau'in siffar ba daidai ba

Tabbatar da siffofin da kuke amfani da su daidai ne, misali ta amfani da wannan lambar don bambanta tsakanin png da jpeg.

Har ila yau, tabbatar da ainihin saƙo daidai ne bisa ga kayan aiki da ake amfani dashi, dangane da aikin tsara hotunan da aka yi amfani

//to generate png image
header('Content-type: image/png');
if(!imagepng($im)) die('Error generating image');
//to generate jpeg image
header('Content-type: image/jpeg');
if(!imagejpeg($im)) die('Error generating image');

Ba a shigar da ɗakin hoton hoto ba

Don tabbatar da ɗakin dakunan karatu. Don yin haka, gudanar da aikin phpinfo (); a cikin rubutun, kuma bincika kayan sarrafawa don darajar da ake danganta da PHP GD, ɗakin da aka yi amfani da shi ta hanyar ayyuka kamar imagepng ();

Idan akwai kunshe da ɓaɓɓuka, hanyar da za a magance shi ya dogara da tsarinka na gida, ta hanyar ƙara kunshin ta amfani da umarnin PEAR, ko amfani da mahaɗar yanar gizon da aka gina a cikin bayani don shigarwa.

Abin da za a yi lokacin da hotunan hoto ko imagepng ba ya aiki

A cikin NotePad ++, bude fayil ɗin PHP wanda ya kira aikin hotunan, da ajiye shi bayan ya shiga menu Tsarin> Sauya zuwa UTF-8 ba tare da BOM ba.

A cikin DreamWeaver, je zuwa Abubuwan Abubuwa> Rubutun> Rubutun / Ciki> kullun Ƙara Unicode Signature (BOM).

A yayin da PHP imagejpeg ko imagepng ba ta aiki ba, yana iya yiwuwa ne saboda gaskiyar cewa fayil ɗin PHP an sanya shi tare da BOM, wani Bill na kayan, sabili da haka ƙarin bayani an aika tare da hoton kafin bayanan hotunan.

Ana amfani da ayyukan PHP da image na PHP da ake amfani dashi don aika lambar hoto a cikin uwar garke.

PHP - imagepng ba aiki daidai ba
PHP - imagepng aiki
PHP - imagejpeg aiki

Similar articles

Sharhis (6)

Irvin Vasquez, 2018-08-19
Simple, clear and well explained, many thanks
Joyce Lawrence, 2018-08-19
ありがとう、非常に有益な
Catherine Roberts, 2018-08-19
Dokładnie tego, czego szukałem, idealnie
Headlinext, 2018-08-19
जानकारी का महान टुकड़ा, साझा करने के लिए धन्यवाद
Marshel, 2018-08-19
विश्वास नहीं कर सकता कि मुझे अंत में समाधान मिला, यह लंबे समय तक एक दुःस्वप्न था, अब हल हो गया
porcateraC, 2018-08-19
بالضبط ما كنت أبحث عنه ، مثالي

Leave a comment