Jpgraph position text at certain x-value position - php

I'm using JPGraph with a simple Line plot.
It's possible to create a text or image and position it vertically and horizontally centered on a point of my line?
Something like:
$txt = new Text("hello");
$txt->SetPosition????("center",$p1->$index,$shift_x,$shift_y);

it is possible to position the text on a specific point in the graph area by
$txt->SetScalePos(x, y);
where x and y are the coordinations on the X and Y axis.

Related

Recalculate the position of a larger object to re-align two different sized objects after rotation

I have 2 images I am placing on top of a 1080X1920 canvas.
One is a rectangle that is 800x400 and it is sitting on the 1080X1920 canvas with top left coordinates of x=140 and y=1200
Then I have another image that is the same size of the canvas 1080X1920, but also has a rectangle on it at the exact same coordinates as the first rectangle. I am overlaying this 1080X1920 image at x=0 and y=0 on the canvas so that the rectangle already in this image lines up perfectly with the rectangle that is already placed on the canvas.
My problem is, I need to apply a rotation to both of these and the black and red rectangles need to match up in positioning AFTER the rotation is applied. Could be any rotation, but let's say it is a 15 degree rotation.
When each element is placed on the canvas and then the 15 degree rotation is applied, the rectangles no longer align because of the difference in image size and the offset in rotation as they both rotate around the center point which looks to be my only option in this case.
So I am hoping to sort out a formula I can use that would rectify the positioning of the 1080X1920 image so that the object already embedded in that image lines up with separately overlaid image.
There are of course other ways to deal with this problem, but right now, they would make things quite a bit more difficult, so I wanted to see if this was possible to calculate first.
I have tried several ways to calculate this, but am not super mathematically proficient, so I am grasping at straws at best.
Oh and because I am not extremely mathematically proficient, any dumbing-down of mathematical terms is appreciated. ;)
Oh and possibly this post answers this question, but I can't wrap my head around whether or not it does, so if someone can let me know if it does, I will try harder to understand and apply it to my particular case.
How to recalculate the coordinates of a point after scaling and rotation?
Any rotation is done around a "center of rotation". You don't tell the centers you use, but they can be:
Center of the canvas.
Center of each image (middle point of its four corners),
Some corner.
Any other point.
If both rotations are not the same, then there's not possible match.
It seems you use the center of each image. Then, to match the second rectangle to the first one, after you rotate the first image you must do in this order:
Translate the second image so its center of rotation is exactly the
same as the center of rotation of the first image. The vector of translation is the coordinates difference for X,Y centers.
Rotate the second image with the same angle as the first image rotation.
This boils down to tracking where the original (0,0) points are on the two images after rotation.
Let's define the problem a bit cleaner:
red.png: 800x400
black.png: 1080X1920
rotate both by 15° (or θ = 15 * π/180) with rotate filter (assuming the actual values are within -90° and 90°)
how to place a rotated red.png on rotated black.png at the ORIGINAL top-left coordinates (x=140,y=120)
Consider 2 FFmpeg rotation commands:
ffmpeg red.png -vf rotate=15*PI/180:ow=hypot(iw\\,ih):oh=ow -frames:v 1 red_rotated.png
ffmpeg black.png -vf rotate=15*PI/180 -frames:v 1 black_rotated.png
Note that red_rotated.png is enlarged to inscribe the red rectangle while black_rotated.png maintains the same size. Now, the question is "where are the original top-left corner now?"
red_rotated.png:
0 < θ < π/2 cases: (xr,yr) = (h sin(θ), 0)
-π/2 < θ < 0 cases: (xr,yr) = (0, w sin(θ))
black_rotated.png: Same as red_rotated.png but now cropped to the original size
new size: ow = w cos(θ) + h sin(|θ|), oh = w sin(|θ|) + h cos(θ)
size delta: dw = (ow - w)/2, dh = (oh - h)/2
0 < θ < π/2 cases: (xb, yb) = (h sin(-θ) - dw, -dh)
-π/2 < θ < 0 cases: (xb, yb) = (-dw, w sin(θ) - dh)
Now, where is the insertion coordinate (x,y) = (140,120) on black_rotated.png:
rotate wrt the original corner: (x1,y1) = (x cos(θ) - y sin(θ), x sin(θ) + y cos(θ)
shift wrt the new black corner: (x2,y2) = (x1 + xb, y1 + yb)
shift wrt the new red corner: (x3,y3) = (x2 - xr, y2 - yr)
Accordingly overlaying red_rotated.png with the offset (x3,y3) onto black_rotated.png should get you the results you want.
Disclaimer: I have not verified my math, but this is should be a good starting point.

How to rotate the text of heading and font color google sheets api

Today i have made a dynamic google sheets as i want to rotate the text of heading how can i rotate heading text so please help me so that i can improove more.
enter image description here
For rotation, you can use the "setTextRottation" function:
// Sets the cells in the ranges A1:A10 and C1:C10 to have text rotated up 90 degrees.
var sheet = SpreadsheetApp.getActiveSheet();
var rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']);
rangeList.setTextRotation(90);
Please refer to the following link for further documentation
https://developers.google.com/apps-script/reference/spreadsheet/range-list#setTextRotation(Integer)

how to print zpl barcode vertically in vertical label

i am using zebraGk420d printer. i am using vertical barcode label. how to print the text and barcode in vertically. my zpl code like this
$barcode_ZPL_code="^XA
^FO 150,50^AD,40^FH^FDSALABED_20CARGO^FS
^FO80,100^AD^BY2
^BCN,100,Y,N,N
^MD10
^FDLTX81316-1(1)-APP^FS
^FO1,250^A0N,20,20^FH^FDCOURIER_20TYPE_3ACHEDDI_20JAGAN_20AIPORT_20GUYANA_20OWN_20CLEARING_20TEST^FS
^FO1,280^A0N,20,20^FH^FDDESTINATION_3ASALABED_202CARGO_20PLOT_20710_20BLOCK_2012_20KISENYI_20ROAD_2E_2E_2E^FS
^FO1,310^A0N,20,20^FH^FDHEAD_20OFFICE_3AUNIT_204A_20ORBITAL_20BUSINESS_20PARK_205_20ARGON_20ROAD^FS
^FO106,340^A0N,20,20^FH^FDEDMONTON_20LONDON_20N18_203BW_20EMAIL_3AINFO_40SALABED_2ECO_2EUK^FS
^FO106,370^A0N,20,20^FH^FDTEL_3A_2B44_28020_29_208884_204060_20WEBSITE_3AWWW_2ESALABED_2ECO_2EUK^FS
^XZ";
This code prints in horizontal format.Thanks in advance.
You can specify orientation for each text/barcode field individually, for example if some fields should print horizontally and others at 90 degrees, or use a default orientation for all fields, and then only specify orientation for exceptions to that rule.
The individual field orientation in your label for text and barcodes are specified in the fourth letter of ^AON and ^BCN commands. To change the orientation of any of these fields, use the appropriate letter from following list:
N = normal
R = rotated 90 degrees (clockwise)
I = inverted 180 degrees
B = read from bottom up, 270 degrees
For example, to print the barcode at 90 degrees, replace ^BCN,.... to ^BCR,..., or to print a particular text line at 90 degrees, replace ^AON,... to ^AOR,....
To change the default orientation of all fields in your label, you can use ^FWx before any text / barcode fields are called out, where x represents the desired default orientation (from above list of orientation options), and only include the orientation letter in individual text / barcode commands (i.e., change ^BCN,... to ^BC,... and ^AON,... to ^AO,...) for any exceptions to that default orientation.
For example, to print all fields at 90 degrees except the last text line you can use the following (notice the added ^FWR command and the orientation letter removed from all text / barcode fields except the last text command):
$barcode_ZPL_code="^XA
^FWR
^FO 150,50^AD,40^FH^FDSALABED_20CARGO^FS
^FO80,100^AD^BY2
^BC,100,Y,N,N
^MD10
^FDLTX81316-1(1)-APP^FS
^FO1,250^A0,20,20^FH^FDCOURIER_20TYPE_3ACHEDDI_20JAGAN_20AIPORT_20GUYANA_20OWN_20CLEARING_20TEST^FS
^FO1,280^A0,20,20^FH^FDDESTINATION_3ASALABED_202CARGO_20PLOT_20710_20BLOCK_2012_20KISENYI_20ROAD_2E_2E_2E^FS
^FO1,310^A0,20,20^FH^FDHEAD_20OFFICE_3AUNIT_204A_20ORBITAL_20BUSINESS_20PARK_205_20ARGON_20ROAD^FS
^FO106,340^A0,20,20^FH^FDEDMONTON_20LONDON_20N18_203BW_20EMAIL_3AINFO_40SALABED_2ECO_2EUK^FS
^FO106,370^A0N,20,20^FH^FDTEL_3A_2B44_28020_29_208884_204060_20WEBSITE_3AWWW_2ESALABED_2ECO_2EUK^FS
^XZ";
Also, you will need to adjust the x/y coordinates once you change field orientation.

PHP: imageftbbox

What is the application of a bounding box of a text in PHP imageftbbox?
In the example of the manual, it was used to determine the coordinates for the imagefttext function. Is it necessary? Maybe I am missing something here.
...
// First we create our bounding box
$bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group');
// This is our cordinates for X and Y
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group');
...
Flylib has extensive information about imagettfbox().
Here's some relevant information from the linked information:
(image copyright Flylib)
From image above, you can see that there are 4 point with 8 information (as the documentation already stated):
Array information Bounding box coordinate
===================================================================
0 X coordinate of the lower left hand corner
1 Y coordinate of the lower left hand corner
2 X coordinate of the lower right hand corner
3 Y coordinate of the lower right hand corner
4 X coordinate of the upper right hand corner
5 Y coordinate of the upper right hand corner
6 X coordinate of the upper left hand corner
7 Y coordinate of the upper left hand corner
Again, as stated by the documentation, this information is relative to text regardless of the angle. Therefore, if you rotate the text to 90 degree clockwise, the bounding box become:
Array information Bounding box coordinate
===================================================================
0 X coordinate of the upper left hand corner
1 Y coordinate of the upper left hand corner
2 X coordinate of the lower left hand corner
3 Y coordinate of the lower left hand corner
4 X coordinate of the lower right hand corner
5 Y coordinate of the lower right hand corner
6 X coordinate of the upper right hand corner
7 Y coordinate of the upper right hand corner
Another resources that I believe will help you better grasp the basic idea around bounding box:
http://ruquay.com/sandbox/imagettf/
the pair of functions imageftbbox and imagettfbbox allow you to know how much space will your text take on an image (the first one is used for free type text and the second for true type text)
this way, if you have an application that generates some images and writes on them variable text (user input or something like this) you can decide how/where to place that text using functions like imagefttext or imagettftext (same difference - the font)
so you can do something like:
$bbox = imagettfbbox(34, 0, 'myriadb.otf', strtoupper($name)); //font size 34, text in a horizontal line, use myriadb.otf as font, the user name as variable text
$text_width = $bbox[2]; // this is how much space the name will take
$margin = (CARD_WIDTH-($text_width))/2; // a constant knowing the width of the resulting card.. this way we will center the name..
imagettftext($image, 34, 0, $margin, $y, $white, 'myriadb.otf', strtoupper($name));// $image resource, 34-same size, same angle, the margin is the the x coordinate, fixed $y, color, font and the same text

save image after some data written on that image

Hi all
i am displaying an image in a div and content in another div.using jquery draggable method, i placed the content in that div on the image. Now i want to save that image with content as an image. Is it possible? please answer this as it is important
It's perfectly possible to do this, but it's not trivial and I won't post all the code necessary to do it. Instead, I'll give you some pointers:
You can't save the added text "as is" client-side. That's not possible. You could take a screenshot of it, but that's probably not what you want.
Instead, you need to save the text value and the position and size of where the text is placed relative to the image.
Use relative values, e.g. x = 0.3242, y = 0.5123, width = 0.5123, height = 0.12, where x = 0, y = 0 is the top left corner of the image and x = 1, y = 1 the bottom right corner, width and height similarily representing a fraction of the image size.
POST this information to the server and recreate the same effect by baking the text into the image using, for example, gd.
For finding the right font size to use, futz around with imagettfbbox until you have found the closest equivalent in size to the target coordinates.
Use imagettftext for writing the text into the image.

Categories