Path points?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
immortal26

Path points?

Post by immortal26 »

I've been searching but can't find anything related, only creating path points.
I was wondering if Imagemagick can get path points from font's.
I would rather not script photoshop to do it (to slow).

What I would be doing is finding the points on a path from a font... and placing a bitmap on each point, that's it.
Always sounds easy but never is, so hope there is a way IM can do it.

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

If you mean "all the points on the path", just use something like "-fill none -stroke black -strokewidth 1".
snibgo's IM pages: im.snibgo.com
immortal26

Re: Path points?

Post by immortal26 »

Well, that would just give me a stroke around my font... can't really do anything with that, or with what I want to do posted above.
I created a font that has point's along a path... think of it as in photoshop, creating a work path from the font then you can actually see all the points on that path.
So foreach point on path place bitmap image. If there is another way to achieve this without using points that would be even better.

I guess I should also explain in detail what I'm trying to do:

I have a stadium shot that shows a stadium field (football) and i have random bitmaps of band members (very small) that will be placed on each point on the path to represent a letter... in the end someones name. So it would look like band members lined up as letters on the field and of course skewed and if the persons name was very large it would also scale (but that would be on my end and I can figure that part out).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

One approach to the problem:

1. Create an image of black text on white backgound.
2. Overlay a series of horizontal and vertical white bands, so the letters are broken up.
3. Erode these black pieces to single points.
4. Apply a perspective transformation (so the word will "lie flat" on the football field).
5. Create a list of coordinates of the black points.
6. Create a large transparent canvas.
7. On this canvas, place one band member bitmap at each coordinate from 5. (Distant bandmembers should be smaller.)
8. Place this canvas over the photograph of the football field.

All of this could be done with ImageMagick and a suitable script.

(EDIT: for extra realism, step 7 should add shadows of the figures.)
snibgo's IM pages: im.snibgo.com
immortal26

Re: Path points?

Post by immortal26 »

Phew, that's gonna be hel* to put together, not sure it will work to good though because there should always be a bandmember at each end point of a letter for example.
the letter A should have a band member at the bottom left bottom right and the top angle.
The lines that you suggest may interrupt some of those I would think... depending on the letter/font.
If you know what I mean.
I also ran across getting SVG info... that might be a possibility?
Here is the link I found about it:
viewtopic.php?f=1&t=14646&p=51201&hilit ... nts#p51201
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

SVG might be part of the solution, eg Inkscape can vectorise a bitmap, or create vector paths directly from text. But this will be the outlines of the letters, where you want the centre-lines of each stroke, including the ends. You need to do an erosion somewhere.

Or you might search the net for a font that is stroke-only, where each stroke has zero thickness. Working from that might be easier.

For a more primitive effect, you could paint each letter with a repeated bitmap of a bandmember. This would be simple with Gimp, and possible somehow with IM.

Your problem is quite complex, with no simple solution. If this is a one-off need, you could do it all manually in Gimp. But an automated solution will be complex.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

For example, the font http://img.dafont.com/dl/?f=electronic_highway_sign is upper-case letters only, each represented by squares in a 5x7 matrix.

Code: Select all

"%IMG%convert" ^
  -background black -fill white -pointsize 610 ^
  -font C:\windows\fonts\EHSMB.TTF ^
  label:"Alan" ^
  -threshold 5%% -bordercolor Black -border 1x1 fb.png

rem Find the top-left in a block of white pixels.
rem
"%IMG%convert" fb.png -morphology Correlate ^
  "3: -1 -1 -1  -1 1 - -1 - -" ^
  fbcorr.png

ren Use the coordinates of the white pixels in fbcorr.png

rem Dilate them and resize image for display purposes
rem
"%IMG%convert" fbcorr.png ^
  -morphology Dilate Disk:10 -resize 400x400 -trim +repage ^
  fbDisplay.png
Image

Converting fbcorr.png to txt and grepping the white pixels will find the required coordinates.
snibgo's IM pages: im.snibgo.com
immortal26

Re: Path points?

Post by immortal26 »

awesome man, that helps alot.
hit a snag in my code prolly on php end... losing color on png somewhere
link to reselts http://kgcore.com/clip.php

code:

Code: Select all

<?php

// Letter D

$d = array(
array(0,0),
array(20, 0),
array(0,20),
array(40, 0),
array(0,40),
array(58, 5),
array(0,60),
array(70, 15),
array(0,80),
array(75, 25),
array(0,100),
array(20, 100),
array(40, 100),
array(75, 45),
array(75, 65),
array(58, 95),
array(70, 85),
);


$final = 'convert -size 200x200 xc:none ';
$i=0;
foreach($d as $bm) {
	$rbm = rand(1,4);
	$final .= 'bm'.$rbm.'.png -geometry +'.($bm[0]+$i).'+'.($bm[1]-$i).' -composite ';
$i+=0;
}
$final .= "d.png";

exec($final, $result);

$final = "convert Florida.jpg d.png -geometry +750+850 -composite final.jpg";

exec($final, $result);

echo "<img src='final.jpg'>";
?>
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

Losing color where? The result looks a bit blue-hazy, but that could be from the original Florida.jpg.

Do the bm.1.png etc files have color? If so, please post one (or all four). Likewise the created d.png -- have we lost the color here?

The generated commands look reasonable. $i doesn't seem to do anything useful. Can you print a debug of $final before the first exec?
snibgo's IM pages: im.snibgo.com
immortal26

Re: Path points?

Post by immortal26 »

Band member bitmaps:

Code: Select all

http://www.kgcore.com/bm1.png
http://www.kgcore.com/bm2.png
http://www.kgcore.com/bm3.png
http://www.kgcore.com/bm4.png
Output from all commands before exec:
Creating the letter D:

Code: Select all

convert -size 100x150 xc:none bm2.png -geometry +0+0 -composite bm2.png -geometry +20+0 -composite bm1.png -geometry +0+20 -composite bm1.png -geometry +40+0 -composite bm3.png -geometry +0+40 -composite bm4.png -geometry +58+5 -composite bm1.png -geometry +0+60 -composite bm3.png -geometry +70+15 -composite bm1.png -geometry +0+80 -composite bm3.png -geometry +75+25 -composite bm4.png -geometry +0+100 -composite bm3.png -geometry +20+100 -composite bm1.png -geometry +40+100 -composite bm1.png -geometry +75+45 -composite bm1.png -geometry +75+65 -composite bm4.png -geometry +58+95 -composite bm1.png -geometry +70+85 -composite d.png
Putting the D on the Background:

Code: Select all

composite -geometry +750+850 d.png Florida.jpg final.jpg
If you go back to http://www.kgcore.com/clip.php and look at the field where the band members are you will see they are all black.

Oh and as for d.png ... http://www.kgcore.com/d.png ... have not lost the color.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

The problem occurs in that second convert:

Code: Select all

convert Florida.jpg d.png -geometry +750+850 -composite final.jpg
Colors are lost, and transparency is ignored (so the edges become hard, "aliased". I can't figure out why, but it's the end of a long day where I live.

The workaround is to create a png version of Florida:

Code: Select all

convert Florida.jpg Florida.png
Do this once, and use that in the convert:

Code: Select all

convert Florida.png d.png -geometry +750+850 -composite final.jpg
This works for me (IM 6.6.0-8 on Windows 7), giving color figures with soft edges.

Incidentally, I generally use convert in preference to composite, but either should work here.
snibgo's IM pages: im.snibgo.com
immortal26

Re: Path points?

Post by immortal26 »

Yes very strange, I almost have the exact same code doing the same exact thing but here for some strange reason... it's not working.
Thank you again for all your help... I think I'm going to just create a font based on x,y coord's assigned to each letter.
Just gotta figure out the correct math depending how the field is facing etc.. a skew but not a whole image because that would distort the band members... so have to do them individually... phew, long day here as well.

Thanks again
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

Happy to help.

I don't have a copy of Florida.jpg; for my testing I've simulated it with result.jpg. That file is CMYK, with an ICC color profile.

Code: Select all

convert Florida.jpg -profile sRGB.icm FloridaRGB.jpg
creates an sRGB version, in RGB colorspace. Using this file in the final conversion retains the colours in the band members. I suspect the problem is CMYK/RGB, not the presence or absence of color profile.

Of course, all the processing should be done losslessly, eg PNG, rather than repeated lossy JPG conversions.


You might want to look at the documentation and source code for "-distort perspective" (source file distort.c), which can stretch a reactangle so the four corners fit on arbitrary coordinates. You can apply the same maths to the coordinates of the band members.
snibgo's IM pages: im.snibgo.com
immortal26

Re: Path points?

Post by immortal26 »

Oh noes i'm back lol.
Well you can take a looksie at what i got going so far
http://www.kgcore.com/mvp/stadium/florida/clip.php
it will redirect you to pdf when it's done rendering.

As you can see it's working pretty good. I'm using the svg to filter through the filled areas to place a band members.
Problem is if you zoom in 100% you will notice there are several band members in each spot. I think i can see svg reads from top y to bottom y and tried to programmatically change it but can't quite get it right since it's at an angle (skewed).

Was wondering if you might have a suggestion or two.. here is the code for that one part (placing the band members).

Code: Select all

$i=0;
$final = 'convert -size '.$width.'x'.$height.' xc:none ';
$none = 0;
foreach ($xml->circle as $s) {
	if ($s['fill']!='none') {
		if ($i == 2) {
			$rbm = rand(1,4);
			$final .= $bm.'bm'.$rbm.$png.' -geometry +'.$s['cx'].'+'.$s['cy'].' -composite ';
			$i=0;			
		}
		else {
			$i++;
		}
	}
}
$final .= 'final'.$png;

exec($final, $result);
The font I'm using is this:
http://www.kgcore.com/mvp/stadium/flori ... /trace.TTF
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Path points?

Post by snibgo »

Good result.

The code looks fine, with the possible exception of the assignment to $final:

Code: Select all

$final .= $bm.'bm'.$rbm.$png.' -geometry +'.$s['cx'].'+'.$s['cy'].' -composite ';
I don't know if php interprets the quotes around cx and cy as you want. I guess it does, or the convert would fail.

Yes, you seem to be getting overlapping band members, even though you are only picking up one circle in three. What does the SVG look like?

Letters in the font are made of dashes (i.e. thin rectangles). What are you using to convert to SVG?

For testing, you might want to temporarily replace bm1.png etc with small coloured dots (different colours, and cycle through them instead of random). For the final result, you could blur the band members more, so the figures resemble those in the crowd.
snibgo's IM pages: im.snibgo.com
Post Reply