Center text on image

See all posts Reply

Center text on image new!
by Vincent, 17 years, 7 months ago
Hello,

Is it also to position the text on a image in the center just like imageshack has?

Best regards,
-VincentReply
Re: Center text on image new!
by colin, 17 years, 7 months ago
You mean some text at the bottom of the picture, in a black line?

It is not possible as of now to add the dimensions or size of the picture there, but it is a feature that I will try to implement in the next version.

For instance, we could imagine this:
$foo->image_text = 'size: [x] x [y]';
where [x] and [y] would be replaced by the dimensions.

In the meantime, you can do as following:
$foo->image_resize         = true;
$foo->image_ratio_y        = true;
$foo->image_x              = 200;
$foo->image_crop           = '0 0 -16 0';
$foo->image_text           = 'some text here';
$foo->image_text_font      = 2;
$foo->image_text_position  = 'B';
$foo->image_text_padding_y = 2;
And you will have the same display as in the picture above.Reply
Re: Center text on image new!
by Vincent, 17 years, 7 months ago
Getting the dimensions and size IS possible :)

Work around:
$imgsize = getimagesize($_FILES['file']['tmp_name']);
$image_uploaded->image_text =
  $imgsize[0].'x'.$imgsize[1].'px - '.
  $image_sizekB.'kB\nHosted by site.com';
Reply
Re: Center text on image new!
by colin, 17 years, 7 months ago
Of course, I know that. Look at the code of the class!

What I meant is that when you us the class text features to add some text, it is not possible so far to print the dimensions of the image in the text. The text that you set in $foo->image_text is printed as it is (i.e. not parsed), nor any keyword is replaced with the actual dimensions.

So you hint that your code could be used to set the text prior to calling the Process() function. But this wouldn't work, as of now, because you don't know the dimensions the image will be in after being resized.

I will add such a feature in the next release. You will then be able to use keywords in $foo->image_text, such as [x], [y] or even [date].Reply
Re: Center text on image new!
by Vincent, 17 years, 7 months ago
Cool, thanks Colin.

I do have one questions, i have a newline in the above text as you see.

However, in the made image \n just appears and not a actual newline.

How is this caused?Reply
Re: Center text on image new!
by colin, 17 years, 7 months ago
You should be able to use a line break. Make sure that your negative margin you set in $foo->image_crop is enough for two lines. Use something like 20 pixels, and you should be able to see the two lines.

Also, make sure that your string is enclosed in double quotes, not single quotes, otherwise the line break will not be interpreted. For instance:
$foo->image_crop = '0 0 -22 0';
$foo->image_text = "some text here\na new line";
Reply