开发者

Dynamically Creating an image with PHP, I don't know its height or the dimensions of its elements before hand

开发者 https://www.devze.com 2023-02-19 01:07 出处:网络
Edit: I was attempting to describe this problem using the markup I\'m currently using, but that seems to be causing confusion. Look at the edit history if you\'d like to see that should the question b

Edit: I was attempting to describe this problem using the markup I'm currently using, but that seems to be causing confusion. Look at the edit history if you'd like to see that should the question be unclear

I would like to write a php script generating an image from user submitted content.

The content is a block of text of undetermined length on a background. The text could be anything from a couple words to a few sentences.

There could be anywhere from 1 to 6 of these blocks of text that will vary in size. So, since the text varies in length, the container/background will vary in height. And since I could have multiple blocks, the开发者_如何转开发 overall image will vary in height.

Given that I need to dymically size so much of this (the image itself, the text containers, possibly font size), and I really don't even know where to start with the GD library, my first questions are:

Is this possible?

If possible, is it feasible to implement without a ton of headache?

Is there a cross-platform alternative (preferably no flash, and likely no <canvas>)?


There is a PHP function that gets the image size and returns it as an array.

$image_data = getimagesize($image_path);

returns an index array with 4 elements:

  • 0: width in pixels
  • 1: height in pixels
  • 2: type as integer (1-GIF, 2-JPG, 3-PNG, 4-SWF, 5-PSD, etc)
  • 3: the string " height='(height)' width='(width)'

You can use the $image_data[0] and $image_data[1] to return the proper width/height, which you can use to dynamically size the containers and whatnot.

The other issues you have are somewhat beyond the amount of time I can put into a post at the moment. Perhaps later I can expound upon those. Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消