开发者

webserver replies to ?q="/path/to/file" with a "path bar" png

开发者 https://www.devze.com 2023-03-05 17:57 出处:网络
I want to write a CGI script that accepts a posix path as a string, and returns a png representing it. Eg:

I want to write a CGI script that accepts a posix path as a string, and returns a png representing it. Eg:


If the script is sent the string /System/Library/CoreServices/Finder.app,

it will return the following png file:

webserver replies to ?q="/path/to/file" with a "path bar" png


An example based in any scripting platform that comes bundled with the Mac is fine by me (Python, Perl, AppleScript, BASH). I might not know it, but I can muddle through to get an idea of what I ne开发者_如何学运维ed to do.

I think what I'm looking for is a way to generate an NSPathCell-style widget, and dump its contents into an image file


Depending on the context, it might be reasonable to use -dataWithPDFInsideRect: instead of generating a PNG.

Of course, if you’re getting an image (especially a pixmap image) of a UI element like this for web use, there’s a 95 % chance that you deserve a punch in the face from the Accessibility Gorilla.


That's an NSPathControl. To take an NSString and split it up into the path components, you can invoke the -[NSString pathComponents] method. If you want that actual png, you'd have to either do the rendering yourself or take an NSPathControl, force it to draw into a context that you control, and then turn that context into an image yourself.

Bigger question: what are you trying to accomplish?


In response to the comment you posted on May 17: since this is a webapp, I would like to suggest writing a script that turns your file path into a styled HTML block that very closely resembles the single image result you originally asked for. You would use static icons for hard disk, folder, file, and the little gray arrow.

This way you could say:

<?php echo prettyPathHTML('/System/Library/CoreServices/Finder.app'); ?>


You can get image data from a path like this:

1) Create an 'NSPathControl'

2) Use the control's 'setPathCtrl:toURLStr:' to have it display the URL of your choice.

3) Call the control's 'getPngDataFromNSView:' and it will give you your desired image data.

4) Now you can save the data to a file using 'writePngData:'

If Obj-C isn't an option, you can use PyObjC bridging from Python.

0

精彩评论

暂无评论...
验证码 换一张
取 消