As many of you may already know I have been having issues with another site copying text from my site. The data is sports results that at first are not fully accurate because data is submitted at the event and people have to type in people's hand writing that can be difficult to read as well as other issues related to transferring data. Currently I am stuffing the text with fake text. It is working in part very well. They are still copying the text, but they are removing the fake text manually (which takes them about 2 hours longer hehe). I want to make it even more difficult for them. I would like to change some of the text automatically to images. This will require them to type these portions out. What is a good premade class for this?
I suppose you could use the GD library, that is bundled with PHP, to generate images from text.
Something like this, for instance, might do (adapted from the example given on the page of imagettftext) :
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Hello, World!';
// Replace path by your own font path
$font = '/usr/share/fonts/truetype/msttcorefonts/verdana.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
die;
But note that using images instead of text has some drawbacks :
on the server side, it requires more work
on the client side :
it'll take more time to load
it will not necessarily use the same fonts as the rest of the site (possibly depending of the brower's configuration)
fonts will not necessarily have the same size as the rest of the site (same note)
using images might not be good for people who zoom -- especially people who don't see well.
How about adding some form of disclaimer to the text ("this text created by xyz.com, on dd/mm/yyyy, for more up-to-date information visit our site")? Use their use of your text as a promotional tool for your own site. Also, get in touch with them, see if they'd be interested in using your site via some form of API, this reduces their workload and allows you a little more control over their use (at least in theory).
My argument is that if the stuff you're writing up is factual there's no copyright infringement (so far as I can tell), and they may appeal to a different audience than your own, so you may as well use them as a promotional tool to broaden your own audience.
Related
I want to create a logo or profile avatar from first letters of name, like Google. Is there any method or service to do it?
I am tried to learn the code about make image with php but it's to hard. One time I found a website about this dynamic image text but I don't find.
Most easy examples you will find online are going to use PHP's imagecreate and imagestring functions, such as this one:
https://phppot.com/php/how-to-convert-text-to-image-using-php/
Here is a quick example-code I've put together based on the above link, that creates an image similar to the Google avatars:
$img = imagecreate(250, 250);
$textbgcolor = imagecolorallocate($img, 52, 152, 219);
$textcolor = imagecolorallocate($img, 255, 255, 255);
$txt = "AB";
$fontfile = "/arial.ttf";
imagettftext($img, 100, 0, 35, 170, $textcolor , $fontfile, $txt);
ob_start();
imagepng($img);
printf('<img src="data:image/png;base64,%s"/ width="100">', base64_encode(ob_get_clean()));
You will need place the arial.ttf fontfile in the same directory as your PHP file for this to work.
However, in most fonts that are aesthetically pleasing, letters do not have the same width. So you will find it difficult to center the text, since you can't use the same X value for the anagram "MM" and "II". I would advise you to use a library that has extended functions like aligning text to the middle, and my bet would be on gd-text.
I tried to merge text with images, but my text not rendering correctly after merge.
See my screenshot:
The Red mark ( আমি তোমায় ভালবাসি ) text format is correct while I normally show the variable. Font Link: http://www.fonts2u.com/solaimanlipi.font
But while I merge text with image, its broken or not render correctly.
Here is my full code:
<?php
mb_language('uni');
mb_internal_encoding('UTF-8');
$username="";
if(isset($_POST['user'])){
$username = $_POST['user'];
$username = mb_convert_encoding($username, 'HTML-ENTITIES',"UTF-8");
$username = html_entity_decode($username,ENT_NOQUOTES, "ISO-8859-1");
}
$im = imagecreatefromjpeg('image.jpg');
//The numbers are the RGB values of the color you want to use
$black = ImageColorAllocate($im, 255, 255, 255);
//The canvas's (0,0) position is the upper left corner
//So this is how far down and to the right the text should start
$start_x = 50;
$start_y = 80;
$font = 'SolaimanLipi.ttf';
Imagettftext($im, 50, 0, $start_x, $start_y, $black, $font, "$username");
//Creates the jpeg image and sends it to the browser
//100 is the jpeg quality percentage
Imagejpeg($im, 'result.jpg', 100);
echo "<div style='color:red;font-size:60px;'>".$username."</font><br /><img src='result.jpg' height='500' />"
?>
Note 1: SolaimanLipi.ttf is Bangla (Unicode) Font.
Note 2: Bangla (Unicode) font not rendering correctly in tcpdf This Stack & Stack solution will help you to understand my problem & give me a solution.
Please someone help me to get out this problem. Thanks in advance.
[[Previously I asked the same question and no one answer. So I re-post this and deleted the old one. I hope this time someone help me.]]
Bengali is one of a number of scripts that cannot be rendered simply by putting one character after the next. The shapes of characters change and merge depending on their neighbours.
To render this correctly, you need a set of features known as Complex Text Layout. On text rendering systems that do not support CTL, you'll get the equivalent of each letter being rendered alone, so আমি comes out like আ ম ি.
The GD library used by PHP's imagettftext function does not support Complex Text Layout. You'd have to use some higher-level rendering library such as Pango. This is a bit of a pain; if you can achieve your aims by rendering the text over the image as part of HTML/CSS/SVG that would certainly be easier.
(BTW writing $username out to the HTML without doing htmlspecialchars() is an XSS security hole, and writing-then-serving the JPEG file is unsafe as it will break if two requests come in at the same time. You should also serve your page/form as UTF-8 by adding <meta charset="utf-8"/> so you don't have to do the crazy dance with mb_convert_encoding/html_entity_decode).
While reading up on the issues merging transparent images in PHP, it seems that everyone is in the "it works" or "it doesn't work" camps. I have found a way to demonstrate each case.
I wish to take a PNG, cut an ALPHA hole in it and then merge it on top of another image. In this case, I cut a hole in an image from google maps, and paste it over a red block. I have two images from google maps. One is of Manhattan and one is of my house. One works, and one does not. The only difference is one was "saved" via a browser.
If you run the code below, you will see the difference in outputs. Does anyone know why the same code would treat two PNG files completely differently? It must be the difference in the PNG files themselves, but then what would it be?
<?php
sometimesworks("https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&maptype=hybrid", "google");
sometimesworks("https://lh4.googleusercontent.com/UQvV_dpBa3_rVf25pvLXKD3OwzF4FtPnHBHkzdWqjCQ5mlFqcFfId9echIgDMv_xYRRYzLaKEXphw7g=w2447-h1106", "myhouse");
function sometimesworks($p_image, $p_prefix)
{
$image_top =imagecreatefrompng($p_image);
$brush = imagecolorallocate($image_top, 0, 0, 0); //create a black brush
imagefilledpolygon($image_top, explode(",", "10,10, 120,22, 80,280, 200, 191"), 4, $brush); //fill a polygon
imagecolortransparent($image_top, $brush); //turn the black to be transparent
imagepng($image_top, './'.$p_prefix.'.transparent.png'); //save the file to confirm that it is working.
//create a big red square
$image_bottom = imagecreatetruecolor(imagesx($image_top), imagesy($image_top));
$red = imagecolorallocate($image_bottom, 255, 0, 0);
imagefill($image_bottom, 0, 0, $red);
imagepng($image_bottom, './'.$p_prefix.'.red.png');
//merge the top onto the bottom.
$out = imagecreatetruecolor(imagesx($image_top), imagesy($image_top));
imagecopy($out, $image_bottom, 0, 0, 0, 0, imagesx($image_top), imagesy($image_top));
imagecopy($out, $image_top, 0, 0, 0, 0, imagesx($image_top), imagesy($image_top));
imagepng($out, './'.$p_prefix.'.out.png');
}
The issue with the above code is that the PNG files were of different type. One was a truecolor image and the other was a palette. The code to merge files differs depending on what is being done.
This is a good reference for the merging of "palette" based PNG files with transparency.
I'm having some problems with a project I'm doing using Google Maps.
I have the map functionality all figured out, and it works great. I want to add dynamically generated icons to the map, and I've figured out how to do that as well using PHP to dynamically add the text I want to the icon image.
However, the icon is changed beyond the text I want added. The border around the original is made much thicker when there is nothing in the PHP code that should be doing anything like that. The image I've attached to this post shows the two icons. The top icon is the original, and the bottom one has the text added to it by my PHP script. Notice the thicker border.
Here's my PHP code:
<?php
// GETS THE NUMBER TO ADD TO THE ICON
$number = $_GET['number'];
// THE SOURCE OF THE ICON THAT I WANT TO ADD THE TEXT TO
$src = $_GET['src'];
header ("Content-type: image/png");
$font = 4;
$im = imagecreatefrompng($src);
// POSITION THE TEXT TO THE PREFERRED LOCATION
$x = 5 ;
$y = 2;
$textColor = imagecolorallocate ($im, 0, 0,0);
imagestring ($im, $font, $x, $y, $number, $textColor);
imagepng($im);
?>
Keep in mind that all of this is working, except the image is changed beyond just adding the text. The icons look much nicer without the really thick border.
I don't know for sure if this is the case but something like this can be caused if your initial image used transparency at the margin to get an effect of rounded corners. if you want to keep the transparency from the initial image you need to research other functions also. something like this should help:
imagealphablending( $im, false );
imagesavealpha( $im, true );
*right after imagecreatefrompng
I 'm trying to add text on a specific image. Its working perfectly but the quality of image is low especially for papyrus.ttf font. How can i improve the quality of text in the image. But i need high quality to print the output.
Here is my code.. its very simple.
header("Content-Type: image/jpeg");
$im = imagecreatefromjpeg("cosmos.jpg");
$black = ImageColorAllocate($im, 0, 0, 0);
Imagettftext($im, 14, 0, 10, 15, $black, 'papyrus.ttf', "Corey and Lisa ");
Imagettftext($im, 14, 0, 10, 35, $black, 'papyrus.ttf', " 1994, june");
Imagejpeg($im, '', 100);
ImageDestroy($im);
Download: http://wneeds.com/gdtest.zip
If imageTTFText fails in Quality, the next step to try is ImageFTText(). It uses the FreeType library to render fonts, which usually means significantly better quality. It needs to be installed and compiled into PHP to work, which it most often is. Try calling the function and you'll see whether that is the case.
If that doesn't do, the next step is using ImageMagick either through the command line, or through the appropriate PHP extension. But try Freetype first, it could already be enough.