I basically have an image of a world map and i would like to place a pin image at a specified pixel co-ordinate ontop of this world map image.
It's for a website, so ideally the solution should be in PHP or Javascript (i'm avoiding Java and Flash as i want it to be as simple as possible).
I had a look at the processing.js library but it is way to big and bloated for just performing this simple task.
Is there a pre-existing Javascript function which will allow me to do this? Or a more simple javascript library that i can use? (processing.js was a bit too advanced for me, i couldnt get it working lol)
In terms of a PHP solution, i would prefer taking the load off the server and onto the client for this task, but i would still like to hear methods for doing it in PHP if they are suitable.
Thanks!
the easiest way to do this is to put pin image over map image and set them position in css like this:
<div style="position:relative">
<img src="map.png" style="position:absolute; top:0px; left:0px; z-index:0"/>
<img src="pin.png" style="position:absolute; top:50px; left:30px; z-index:1"/>
</div>
I suggest using the GD Library Extension for PHP. From this you can manipulate images and produce a new output. Then you can either cache it somewhere and redirect the user, or serve the image by tweaking the output headers and writing the binary data out to stdout.
header("Content-Type: image/jpeg");
As Aren mentioned, GD is good for this.
However, an alternative to the GD Library is Imagemagick. This gentle introduction is very helpful.
ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
Do you really have to have that 'pin image' in the image itself? Simple HTML & CSS (absolute positioning) would solve this very nicely with practically no load for everyone involved, with the only downside the image is not saveable with the overlaying image included.
Related
I have to create some nicely formatted charts (bar and 3D pie) from dynamic data using PHP 5.3 and for output as PDF report. The report is not to be rendered to the screen at all. I have made the charts using pChart2 as .png files and imported them using tcpdf. The system works, but the quality level is poor, rendering text as a graphic causes the font edges to be blurry etc. when printed. I tweaked the image size of the .PNG output, and it made some improvements but it increases the file size, and the text still looks blurry.
So what I am after is a library to create charts using PHP that can be exported to .svg or .eps format, so elements are drawn by the printer and render sharply for print. Using TCPDF I have imported our logos that are in .EPS format, and the difference between the images is quite marked.
I have seen there is a library called ezcomponents that i can give a try. But before I dive in, is there any advice on what to try before proceeding?
I have had reasonable success rendering the images on a canvas that is two to three times larger than what I ultimately need and then, once I'm finished, using the imagecopyrresampled() function to copy the large image onto a canvas with smaller dimensions, which I save as a png and add to the PDF file. The dithering is pretty good and curved lines, in particular, benefit greatly from this approach. Text might not benefit quite as much, but its worth trying, because it should require very few changes to your code to experiment with this approach.
I would like to create PNG images using PHP on a website. These shall be printed at a defined scale. So I would like to set the DPI value of the images using PHP directly. Unfortunately I did not find any function call for this.
Is there any function that can set/update metadata of PNG files?
Maybe an other solution is more reasonable as using a HTML-Wrapper with CSS style sheet for printing which externally defines the resolution. But I would prefer the "directly on the image" approach...
PNGs can contain arbitrary headers. If you look at the PNG specification, you can add tEXt blocks (which are called chunks) to a given PNG. See section 4.2.3 of the specification for more information on tEXT chunks.
As an example, Adobe Photoshop adds meta XML to its PNGs. I'm not sure if GD supports this, but I'd look there to start. It's definitely possible.
Here is some PHP code that deals with parsing PNG chunks. It might steer you in the right direction. http://code.svn.wordpress.org/imagelibs/libpng.php
Here's an screenshot for a text editor of a PNG, showing the XML that was generated by Photoshop. https://stackoverflow.com/a/14356339/278976
THe pHYs chunk (Physical resolution) lets you set a DPI (well, actually pixels by meter, but it's just a unit conversion). Of course, the PNG reader might ignore it.
PHP does not include (AFAIK) support for reading/writing full PNG metadata, you must do it yourself, see eg
The easiest way is to use ImageMagick, as suggested in this answer. If You want to set PNG resolution in pure PHP, you may look at my answer to the similar question.
In PHP, it's quite easy to use GD to draw text onto a raster canvas in a certain font (according to a TTF file held on the server), and output it as a PNG or JPEG.
I want to do roughly the same thing, but to draw the text as a vector outline and output it as an SVG.
(I do not want to embed the font itself in the resulting SVG, as the font is not licensed for that.)
Is there any PHP library that provides this sort of functionality?
It's possible to script inkscape to do this.
The following command opens "example.svg" and selects all shapes in the file and converts them to paths, and then saves and closes the file.
inkscape --verb EditSelectAll --verb ObjectToPath --verb FileSave --verb FileClose example.svg
I was able to find CleverSVG trough searching, however I did not try this myself, and I am unsure if it will be able to draw text without forwarding the font.
I am looking for a solid PHP thumbnail generating class. Does anyone know any good ones that are open-source?
I could write one, but I really don't want to. The one thing I hate most about PHP is manipulating images with GD and Imagemagick.
Does anyone have any suggestions?
Use phpThumb(). Its a script that internally uses GD library and/or ImageMagick (whichever is available and whichever it thinks is best for the job) to perform basic image manipulation tasks, including thumbnail generation and square thumbnail generation.
You can use it like this:
<!-- best fit -->
<img src="/phpThumb/phpThumb.php?src=/path/to/image.jpg&w=64&h=64">
<!-- crop fit (square thumbnails) -->
<img src="/phpThumb/phpThumb.php?src=/path/to/image.jpg&w=64&h=64&zc=1">
It has built in caching engine so second time a browser requests the above image it is served from its own cache instead of re-generating the thumbnail every time. Though, you may want to spend an hour or so configuring it.
use class.upload.php
see this link for details may be its help you more
http://www.verot.net/php_class_upload_samples.htm
Generating a thumbnail requires so little code that it is a "simple example" of the GD library's resizing functions in the manual:
http://php.net/manual/en/function.imagecopyresampled.php
Just copy and paste.
I am working on a website in which the client wishes to have users upload background images to a printable design, crop to size, add text. Do this to multiple pages then generate a pdf of the 'book'
I am running into the following issues/questions and just need to see where I can start
Are there any PHP developer packages that can do something similar. I have seen jquery crop tools but something also for adding text to an image?
How would I keep the resolution up? If the final cropped with text image needs to be 150dpi, when cropping I am guessing I would have them working on a 72dpi image, then somehow apply the crop and changes to the large image?
If the resolution issue wasn't a big deal I would go about it this way:
Simple image upload
Use jquery to crop photo to correct dimensions
Mess around with gdlibrary and imagettftext() to get the text onto an image (page)
Use something like FPDF to create a pdf from each 'page'
Is this the right way to go about it and any thoughts on the resolution issue. Thank you for any help!
Your primary tool should be ImageMagick. ImageMagick can do the cropping, resizing, scaling, overlay text or graphics, combining images, and apply special effects. A big advantage of using a separate tool instead of PHP's image manipulation tools is that you can do the same transforms in batch through other mechanisms, or even hand the work over to another server to keep the website more responsive. And if you do want to integrate it tightly into the website, you can use the MagickWand For PHP interface.
Cropping does not change DPI, only the dimensions of the image. Scaling, on the other hand, changed both.
You should take a look at Gallery, a GPLed program with some of the functionality you're looking for, and written in PHP.
domPDF is a good tool for converting HTML to a PDF. this way you can use the image they upload as a background image, then put the text over it in any standard HTML tag.
As far as the resolution/dpi issue goes, I'm not sure if there is much you can do outside of changing the size of the image. I would recommend looking into This PHP Library, which has a lot of good tools for manipulating images.
I think with a combination of these tools, you'll be able to create HTML that can make a PDF that's fit to print, and use that.