There may be times you need to find the bounding box of an SVG path. One way to find it would be to parse the path and then apply any group transformation on it to find the range of X and Y coordinates the object occupies. However that’s a bit of code, and I’m quite a bit lazy, so I decided to try another approach: rasterize the path object by itself and find where in the image it was drawn.
Continue reading
Posts Categorized: php
Resize and Crop to a specific width x height with a crop suggestion point.
I really don’t have a shorter description for this. I was working on a personal project the other day and realized that this might be a nifty function. Basically, you know all those snippets to make cropped thumbnails (squares and the like), and how most of them either center or crop to the top of an image. I wanted a new function that would crop to most any size I desired and any position on the image I desired without the need to change any code, only parameters. And thus img_resize_crop was born.
Embed Album Art into an MP3 with PHP
An odd quest perhaps: but adding album art to an MP3 (in ID3 tags) is readily doable with the KTaglib extension for PHP. Once you have it, you can use a script like this to add artwork to an MP3:
$mp3 = new KTaglib_MPEG_File('2.mp3'); $idv2 = $mp3->getID3v2Tag(true); $album = new KTaglib_ID3v2_AttachedPictureFrame(); $album->setType(KTaglib_ID3v2_AttachedPictureFrame::FrontCover); $album->setPicture('testalbum.jpg'); $album->setMimeType('image/jpeg'); $idv2->addFrame($album); $mp3->save();
Assuming no exceptions are thrown, this should allow you to set an image of your choosing as a FrontCover image (of course replacing my example values with your own real values), consult the KTaglib documentation for more details and check “Predefined Constants” for the other image types.
SVG to online coloring-sheet SWF
You can do quite a bit of unorthodox stuff with PHP. If you head over to epbsoft.com, you’ll find several flash coloring sheets I made with PHP, not Flash. (Sort of anyway.) I make them by first creating specially formatted SVG (Scalable Vector Graphics) files and feeding them to a PHP script that writes ActionScript files that are then compiled by MotionTwin ActionScript compiler. As far as capabilities, it’s not all that capable. I have to jump through a couple of hoops to make an SVG that my ActionScript generator can actually parse properly, but when it works, I like the results.
svg-to-coloring.php.zip <– The source code is available if you want to take a look at how it works.
MongoDB looks Interesting
I might take a look at installing MongoDB on my server. I like the idea of a document-driven, NoSQL database, especially after working with relational SQL databases for years, and MongoDB looks interesting. You can read more about it in Developing scalable PHP Applications using Mongo DB. What caught my interest is how flexible using it appears to be from the linked article. Plus, using something other than a SQL database could be a nice change of pace. I HATE adding fields to a SQL database table, and it looks nearly painless in these examples.
Another thing that seemed as though it were worth looking into is it’s apparently designed with storing whole files in mind. I’ve stored files in MySQL databases before, but MySQL really isn’t designed with that in mind, but at the same time, if I’m going to be making a lot of small binary files, I don’t like them cluttering up my directories.