Jump to content

Text outputted with GD is pixelated and ugly


Fabis94

Recommended Posts

Using the image*() function (depending on your format, png, jpeg, etc.. whichever one you're using) you can specify the quality of the image. Trying increases the quality.

 

What do you mean? I don't see an argument for changing the quality :/

EDIT: Nvm found it, but it requires you to save the file. I don't need to save the file.

 

Also on my own computer (when i run stuff on localhost) everything looks fine, but when i transfer it to another server the text looks completely different. What's wrong?

Link to comment
Share on other sites

I have uploaded EVERYTHING. Which means that everything that i have on my PC is on the server (including the font).

 

The text uses the font on the server, it's just that it's messed up. Here's how it looks on my PC:

 

http://i26.tinypic.com/dvaer.png

 

And here's how it looks on the server (remember, that all the files are uploaded):

 

http://i26.tinypic.com/xdi7ft.png

 

What i noticed is that the filesize is different aswell. So wtf

Link to comment
Share on other sites

Using the image*() function (depending on your format, png, jpeg, etc.. whichever one you're using) you can specify the quality of the image. Trying increases the quality.

 

What do you mean? I don't see an argument for changing the quality :/

EDIT: nevermind found it, but it requires you to save the file. I don't need to save the file.

 

That's not true:

 

The path to save the file to. If not set or NULL, the raw image stream will be outputted directly.

 

You simply pass null as the second parameter, something like this:

 

imagepng($im, null, 0);

Link to comment
Share on other sites

Yeah i found that, and i found out that quality isn't the problem. Look at my post before yours:

 

I have uploaded EVERYTHING. Which means that everything that i have on my PC is on the server (including the font).

 

The text uses the font on the server, it's just that it's messed up. Here's how it looks on my PC:

 

http://i26.tinypic.com/dvaer.png

 

And here's how it looks on the server (remember, that all the files are uploaded):

 

http://i26.tinypic.com/xdi7ft.png

 

What i noticed is that the filesize is different aswell. So wtf

Link to comment
Share on other sites

I still think it's a problem with the font.  Since you still haven't posted any code, I'm still just guessing here...I'm guessing you are using imagettfbbox and/or imagettftext?

 

Are you using the same version of the GD library on your localhost as your server? 

 

If it is a different GD version you may need to adjust the path/to/fontfile and/or how you specify the font size (unit-wise).

Link to comment
Share on other sites

I found out that the versions are different. So how do i adjust the code to output the picture as it does on my computer? (my computer has a newer version).

 

Ok and here's the code:

 

header("Content-type: image/png");
$font = 'digitalix.ttf';
$textfont = 'lsans.ttf';
$fontsize = 8;
$image = imagecreatetruecolor(350, 170);
imageantialias($image, false);
$base_img = imagecreatefrompng('base.PNG');
imagecopy($image, $base_img, 0, 0, 0, 0, 350, 170); 
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

(...)
imagettftext($image, $fontsize, 0, 71, $y, $white, $font, $text); //One of the functions, no point of posting them all
addBorder($image, 0, 0, 0);
imagepng($image);
imagedestroy($image);

Link to comment
Share on other sites

okay well the font seems to look the same in both of those screenshots and in your code you don't specify a path/to/font at all so I assume that your fonts are in the same dir as your script and the font itself is shiny. 

 

Your computer has GD2 so fontsize is measured in Points (pt). Your server has GD1 so fontsize is measured in pixels (px).  8pt == 10px so you need to change

 

$fontsize = 8;

 

to

 

$fontsize = 10;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.