I want to put number on a image dynamically - php

I want to put number on a image dynamically.

Take two div's. Set backgroung image for one div and put some number on another div. Place the second div on first div by using css properties like position, z-index

There are 2 ways of doing that:
1.) In the client-side:
You can use the HTML5 CANVAS API. This API allows you to draw arbitrary shapes and images inside a canvas element that is rendered into the browser. So to solve your problem you could load an image inside the canvas and after that draw a number on top of it.
2.) In the server-side:
You will load the image and after that draw the number inside of it using a server-side application. Eg. an application developed using PHP, ASP.NET, Python, etc. In PHP you can use the GD library to do that.

Related

What is the best way to create PDF in PHP to look the same as DOM element?

I want to create a PDF file out of a part of my DOM with a field (div width and height given) and place inside fields with text (position them relatively to this div).
Also I need to be able to rotate those text layers and apply skew on them.
Tried to use TCPDF and mPDF but unfortunately I couldn't achieve it.
Any ideas how to do it and which library would be the best?
With mPDF/TCPDF, you cannot use simple div and style to build page like as HTML. The way is to use table
If you want to use major of CSS 2 features, i thinks you can use the DOMPDF librairy

drawing flow chart using php

I want to dynamically create a visual flow chart using php on web.
I tried to use iMagick extension to draw rectangles, lines, and etc.
However, I ran into a problem that all the drawings have to be on an image and that makes my html code not appear on screen.
So I searched if there is a flow chart extension or functions I can use which I failed.
Is there any flow chart making library/application that I can use with php to dynamically draw flow chart on web?
If not, is there a way to have plain html texts above the image I created with iMagick extension so I can see my html texts positioned at the same spot as the rectangles I made using iMagick?
What is generally done is you have two files, one with the page contents, and the other that is the image, then you embed the image like you would a regular image (<img> tags).
Say you have index.php which is your main page, and you have image.php that has your flowchart code. On index.php you embed the image like this:
<img src="image.php" alt="flowchart" />

function to calculate display height of html+css

(Following this question: html columns whose width automatically changes according to their content )
From a PHP script, I print some HTML code, and I would like to know what will be the height of the result (for paging calculation). Suppose I have the following input:
$html code I want to print (string);
$css code, with full details of the font and size of all items that appear in the HTML (string);
all relevant browser settings (fonts, sizes, etc.);
page $width, in pixels (int).
I create a page that looks like this:
<html>
<head>
<style>$css</style>
</head>
<body style='width:$width'>
$html
</body>
</html>
I want to know, from within the PHP script, the number of pixels from the top of the page to the bottom of the text.
EDIT: I need to do this on the server side, before the content is displayed, because I use this to calculate what content to put. For example, if the content is too high, I might decide to put only the first half, etc.
Another possible use is to calculate what width is needed to achieve a particular height. For example, I might try to put it in a div with width 200px, but then the result may be too high; then I try width 400px, etc., until I find the width the gives the height that I want.
If you want to create your own server-side browser, you will have problems with load time. And if this is not a big problem, you can parse css (something like this: link) to find out what paddings, margins, fonts, line-heights and so on used in your $html variable, then, if you know font specifics, you can try to calculate content height (naturally given, from what browser the user entered).
You might be able to use the TCPDF class to do this. According to this thread the class has limit support for CSS but if your styles are supported the idea would be to examine the current positions, (GetX() and GetY()) before and after a writeHTML method call.
HTML rendering is done at client-side while PHP resides at server.
As such, PHP cannot determine HTML element height from server-side.
You would, however, be able to obtain that using JavaScript.
See: Get full height of a clipped DIV

Export div content to image

Currently I'm working on a project in which user of website can design a giftwall by drag and drop of gifts. Drag, drop and sorting works perfect and I'm able to store generated giftwall into database. On recipient side system lists all the gift images in the same sequence sender sent so it visually looks like a giftwall. I want to allow users to store this giftwall into a single image so they can store their giftwalls into image album. In current system it lists all individual gifts into a individual div resided in main wrapper div. How can I export this wrapper div to image so it looks same as HTML. Any help will really be appreciated. Waiting for reply.
Thanks!
I don't know if there is a way by using pure javascript, but you can generate the image on your server and send it back.
I have never heard of saving browser's viewport to an image file via JS. I think it's only possible vie creating SVG or using HTML5 canvas.
I asked exactly the same thing a while back.
HTML div to screenshot?
The conclusion is... it is not possible with JS. Questionably possible from PHP also.
Use can use an online service for screen capture, like browsershots, but its not in real-time, and doesn't render everything well.
I used a workaround for my situation.
Recreated all the DOM/HTML elements which create the image (load parameters form database, and generate the DOM). Wrap everything in one container div, and zoom it out to the size you need.
I know, not the prettiest solution, but the only solution I could get to work.
Using <canvas> you can create image that will looks similar to how it looks on the page. Try it this way:
Get the size of wrapper <div> and create the same canvas element. Then get the position of each image in the div wrapper and draw that image on canvas at the same position with the same size.
Things may be harder if you need to draw additional controls, like button or textbox.
All modern desktop browsers suport <canvas> now.
You can either use html2canvas, which isn't perfect yet. Or store browser offsets of elements in div and then with GD or ImageMagick combine them into an image
Maybe this could be of use: http://html2canvas.hertzen.com/

PHP - Create image from other images

I want to allow a user to drag some images into a div (using jquery ui draggable / droppable)
When they have positioned the images they can hit save and the content of that div (the images in their relevent positions) is saved as one large image.
Is this possible?
or would I need to store the positions of each element / image 9somehow) then "re-create" the positons that way?
You would need to store the location (x, y, z if that matters) using javascript, and then pass those values, as well as the images to your server-side php code, where you would use imagemagik to create the image.
It's definitely possible but may be unnecessary, as you say you could simply store the position of each div and reconstruct the composite image in HTML later. That would be simpler.
You tagged ImageMagick here but you wouldn't need it - the standard PHP GD functions would be perfectly adequate.
So you'd need something like:
Javascript for dragging and dropping images
AJAX to save the position of each (x, y and a z-index) to the server
When viewing the image later, simply re-render the divs as they were saved

Categories