Image - GD Library
Ik heb een script die een tweet op een afbeelding zet. Als ik hem lokaal opsla werkt hij perfect, zodra ik het vraag om hem te outputten, loopt het mis.
Dit is mijn error:
Quote:
enzo verder<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/stefagm12/domains/seaslug.nl/public_html/api/api.php:1) in <b>/home/stefagm12/domains/seaslug.nl/public_html/api/api.php</b> on line <b>3</b><br />
����JFIF��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
��C
$.'�`=����l��˫MB;��^�ꘊnrT��p
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/stefagm12/domains/seaslug.nl/public_html/api/api.php:1) in <b>/home/stefagm12/domains/seaslug.nl/public_html/api/api.php</b> on line <b>3</b><br />
����JFIF��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
��C
$.'�`=����l��˫MB;��^�ꘊnrT��p
Api.php:
Quote:
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
37
38
39
40
41
42
43
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
37
38
39
40
41
42
43
<?php
str_replace("<br />", "");
error_reporting(E_ALL);
ini_set('display_errors', '1');
if(isset($_GET['naam'])){
header( 'Content-type: image/jpeg' );
$naam = $_GET['naam'];
include_once('test.php');
$twitter = new getTweet;
$get = $twitter->ask("http://rody.vdpol.net/twitter/tweets_json.php?screen_name=" . $naam . "&count=1&include_entities=1&include_rts=1");
foreach($get as $tweet)
{
$test1 = "Auteur: " . $naam ."";
$test3 = "Tweet: " . $tweet['text'] . "";
}
$fotonaam = "twit.jpg";
$fotonaamnew = "" . $naam . ".jpg";
$im = imagecreatefromjpeg($fotonaam);
$stamp = imagecreatetruecolor(300, 130);
$im = imagecreatefromjpeg($fotonaam);
imagestring($stamp, 9, 20, 20, $test1, 0xFFFFFF);
imagestring($stamp, 3, 20, 40, $test3, 0xFFFFFF);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
imagejpeg($im);
imagedestroy($im);
}
else
{
echo "Er is geen gebruikersnaam ingevuld!";
}
?>
str_replace("<br />", "");
error_reporting(E_ALL);
ini_set('display_errors', '1');
if(isset($_GET['naam'])){
header( 'Content-type: image/jpeg' );
$naam = $_GET['naam'];
include_once('test.php');
$twitter = new getTweet;
$get = $twitter->ask("http://rody.vdpol.net/twitter/tweets_json.php?screen_name=" . $naam . "&count=1&include_entities=1&include_rts=1");
foreach($get as $tweet)
{
$test1 = "Auteur: " . $naam ."";
$test3 = "Tweet: " . $tweet['text'] . "";
}
$fotonaam = "twit.jpg";
$fotonaamnew = "" . $naam . ".jpg";
$im = imagecreatefromjpeg($fotonaam);
$stamp = imagecreatetruecolor(300, 130);
$im = imagecreatefromjpeg($fotonaam);
imagestring($stamp, 9, 20, 20, $test1, 0xFFFFFF);
imagestring($stamp, 3, 20, 40, $test3, 0xFFFFFF);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
imagejpeg($im);
imagedestroy($im);
}
else
{
echo "Er is geen gebruikersnaam ingevuld!";
}
?>
Test.php:
Quote:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
class getTweet
{
function ask($url)
{
$info = file_get_contents($url);
$string = json_decode($info, 1);
return $string;
}
}
?>
class getTweet
{
function ask($url)
{
$info = file_get_contents($url);
$string = json_decode($info, 1);
return $string;
}
}
?>
Gewijzigd op 14/04/2014 14:55:12 door Sea Slug
Maar je hebt in ieder geval tekst voor een header staan. Dit komt ook wel is voor omdat je het verkeerd opslaat. Sla je bestanden op als 'UTF 8 without BOM'
Je bent een script aan het maken dat binaire data genereert in het jpg formaat. Het heeft dan geen enkele zin om fouten op het scherm weer te geven. Dat zou enkel leiden tot een ongeldige JPG indeling.
Als alternatief zou je fouten kunnen wegschrijven naar een logfile als je er helemaal niet uitkomt.
Of je schakelt tijdens het debuggen regel 7 en 36 uit, er wordt dan geen image meer uitgespuugd en je kunt dan weer tekst uitspugen. Maar het is of tekst of binaire data.
regel 1 tm 3 kunnen van mij dus weg of zet error_reporting juist bewust op 0.
ook de echo op regel 41 kan weg.
Of je doet het zo:
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
$debug = true; // false als alles goed lijkt te werken
error_reporting(0);
if($debug)
{
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
if(isset($_GET['naam'])){
if(!$debug)
header( 'Content-type: image/jpeg' );
$naam = $_GET['naam'];
include_once('test.php'); // <========== wat is dat? toch geen output he?
$twitter = new getTweet;
$get = $twitter->ask("http://rody.vdpol.net/twitter/tweets_json.php?screen_name=" . $naam . "&count=1&include_entities=1&include_rts=1");
foreach($get as $tweet)
{
$test1 = "Auteur: " . $naam ."";
$test3 = "Tweet: " . $tweet['text'] . "";
}
$fotonaam = "twit.jpg";
$fotonaamnew = "" . $naam . ".jpg";
$im = imagecreatefromjpeg($fotonaam);
$stamp = imagecreatetruecolor(300, 130);
$im = imagecreatefromjpeg($fotonaam);
imagestring($stamp, 9, 20, 20, $test1, 0xFFFFFF);
imagestring($stamp, 3, 20, 40, $test3, 0xFFFFFF);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
if(!$debug)
imagejpeg($im);
imagedestroy($im);
}
else if($debug)
{
echo "Er is geen gebruikersnaam ingevuld!";
}
?>
$debug = true; // false als alles goed lijkt te werken
error_reporting(0);
if($debug)
{
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
if(isset($_GET['naam'])){
if(!$debug)
header( 'Content-type: image/jpeg' );
$naam = $_GET['naam'];
include_once('test.php'); // <========== wat is dat? toch geen output he?
$twitter = new getTweet;
$get = $twitter->ask("http://rody.vdpol.net/twitter/tweets_json.php?screen_name=" . $naam . "&count=1&include_entities=1&include_rts=1");
foreach($get as $tweet)
{
$test1 = "Auteur: " . $naam ."";
$test3 = "Tweet: " . $tweet['text'] . "";
}
$fotonaam = "twit.jpg";
$fotonaamnew = "" . $naam . ".jpg";
$im = imagecreatefromjpeg($fotonaam);
$stamp = imagecreatetruecolor(300, 130);
$im = imagecreatefromjpeg($fotonaam);
imagestring($stamp, 9, 20, 20, $test1, 0xFFFFFF);
imagestring($stamp, 3, 20, 40, $test3, 0xFFFFFF);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
if(!$debug)
imagejpeg($im);
imagedestroy($im);
}
else if($debug)
{
echo "Er is geen gebruikersnaam ingevuld!";
}
?>
Gewijzigd op 14/04/2014 15:45:40 door Frank Nietbelangrijk
Thanks. Zodra ik jouw script toepas, is de pagina helemaal leeg. Geen errors en geen afbeelding.. :s
wat staat er in test.php ?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
class getTweet
{
function ask($url)
{
$info = file_get_contents($url);
$string = json_decode($info, 1);
return $string;
}
}
?>
class getTweet
{
function ask($url)
{
$info = file_get_contents($url);
$string = json_decode($info, 1);
return $string;
}
}
?>
http://www.pfz.nl/forum/topic/10571-afbeelding-tweets-op-afbeelding/
De foutmelding is helder: /home/stefagm12/domains/seaslug.nl/public_html/api/api.php:1
op regel 1 staat output.
Daar moet je beginnen met zoeken.
De foutmelding is helder: /home/stefagm12/domains/seaslug.nl/public_html/api/api.php:1
op regel 1 staat output.
Daar moet je beginnen met zoeken.
en wat is je uiteindelijk doel? wil je de profielfoto's op je website tonen? wil je ze opslaan op je eigen server?
want in die array ($get) staan gewoon url's naar de afbeeldingen zoals
http://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png
Toevoeging op 14/04/2014 17:41:44:
Deze werkt al is het nog verre van ideaal:
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class getTweet
{
function ask($url)
{
$info = file_get_contents($url);
$string = json_decode($info, 1);
return $string;
}
}
$debug = false; // false als alles goed lijkt te werken
error_reporting(0);
if($debug)
{
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
if(isset($_GET['naam'])){
if(!$debug)
header( 'Content-type: image/jpeg' );
$naam = $_GET['naam'];
$twitter = new getTweet;
$get = $twitter->ask("http://rody.vdpol.net/twitter/tweets_json.php?screen_name=" . $naam . "&count=1&include_entities=1&include_rts=1");
$fotonaam = $get[0]['user']['profile_image_url'];
$fotonaamnew = "" . $naam . ".jpg";
$im = imagecreatefrompng($fotonaam);
$stamp = imagecreatetruecolor(300, 130);
$im = imagecreatefrompng($fotonaam);
imagestring($stamp, 9, 20, 20, $test1, 0xFFFFFF);
imagestring($stamp, 3, 20, 40, $test3, 0xFFFFFF);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
if(!$debug)
imagepng($im);
imagedestroy($im);
}
else if($debug)
{
echo "Er is geen gebruikersnaam ingevuld!";
}
?>
class getTweet
{
function ask($url)
{
$info = file_get_contents($url);
$string = json_decode($info, 1);
return $string;
}
}
$debug = false; // false als alles goed lijkt te werken
error_reporting(0);
if($debug)
{
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
if(isset($_GET['naam'])){
if(!$debug)
header( 'Content-type: image/jpeg' );
$naam = $_GET['naam'];
$twitter = new getTweet;
$get = $twitter->ask("http://rody.vdpol.net/twitter/tweets_json.php?screen_name=" . $naam . "&count=1&include_entities=1&include_rts=1");
$fotonaam = $get[0]['user']['profile_image_url'];
$fotonaamnew = "" . $naam . ".jpg";
$im = imagecreatefrompng($fotonaam);
$stamp = imagecreatetruecolor(300, 130);
$im = imagecreatefrompng($fotonaam);
imagestring($stamp, 9, 20, 20, $test1, 0xFFFFFF);
imagestring($stamp, 3, 20, 40, $test3, 0xFFFFFF);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
if(!$debug)
imagepng($im);
imagedestroy($im);
}
else if($debug)
{
echo "Er is geen gebruikersnaam ingevuld!";
}
?>
Toevoeging op 14/04/2014 17:43:39:
als je wilt zien wat er in die array $get zit doe dan:
Ik heb ondervonden dat het aan de BOM ding lag, die rare tekens zijn nu dus weg. Nu staat er dat de afbeelding beschadigt is. Hoe los ik dit op?