25 Sep 2009

selecting just an image in hover as an attribute


in the blogs i have pictures as links to big versions of the picture and i have text links. The text links i want to highlight when you hover over them, but the pictures not.

After a bit of fiddling around, this is what eems to work...

in the css file



/* create a special class for images so they don't get annoying colour blocks when hovered over */
#blog_content a.imagehc:hover {color: white; background: white; }



and then in the html file...


<a href="images/first block detection screen.JPG" class="imagehc"<img src="images/first block detection screenSML.jpeg" alt="some placeholder words for the tool tip" />


(Link for this specific entry...)

11 Aug 2009

Tims aide memoire for CSS.....


Every time I return to CSS I seem to struggle to get the syntax in my head so I thought I'd make a little example page of the major construction types.





The output of the following HTML/CSS examples/both HTML and CSS are validated as ok by the validator

Here is the HTML File...



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Tim's Example Page of CSS declarations</title>
<link type="text/css" rel="stylesheet" href="examples.css" />
</head>

<body>
<h5>Tim's example page</h5>
<p>Hello World</p>
<h1>I am heading 1</h1>
<h2>I am heading 2</h2>

<table>
<tr><th>column1</th><th>column2</th></tr>
<tr><td>no para</td><td><p>para</p></td></tr>
</table>

<h3>I am heading 3</h3>
<h4>I am heading 4</h4>
<p id="onlyoneid">There is only one use of this selector</p>
<p class="multipleuses">There can be lots of use of classes</p>
<h1 class="multipleuses">like this</h1>


</body>
</html>


Here is the CSS file...


/* define all text as black */

body { color: black; }

/* define all the <p> tag entries as red */

p { color: red; }

/* define all h1 and h2 tag entries as green */

h1, h2 {color: green; }

/* define all paragraphs in table data elements as blue [a contextual selector]*/

td p {color: blue; }

/* define all h3 and h4 entries as grey and italic [known as grouping selectors]*/

h3, h4 {color: gray; font-style: italic;}

/* define h4 as bold too - show that multiple css statements can refer to one tag type*/

h4 { text-decoration: underline; }

/* define id selector onlyoneid - ids only used once so that javascript and others can locate the exact point in the page */

#onlyoneid { color: yellow; }

/* define class multipleuses which can be used wherever you like */

.multipleuses { text-decoration: underline; }



And while we are at it here are some other useful links for HTML/CSS

example blank HTML pages

special HTML characters

CSS validator


(Link for this specific entry...)

10 Apr 2009

Silly characters showing on web page.


If you are using a standard UTF 8 font then when writing it is important to avoid smart quotes.

A useful tip if you are using textwrangler is to show invisibles.


(Link for this specific entry...)

4 Mar 2009


(Link for this specific entry...)

2 Nov 2008

The good and bad of the internet

One of the big things that has changed since I last programmed is the Internet.

The ability to log on and find some discussion or code fragments that do what you are trying to do,
or to answer the questions you are trying to answer is fantastic.

At the moment I am trying to get the blog writing app to write out resized images - I don't want to
draw them on screen only load them and save them again.

Now this requires me to use the class NSImage - one that is not in the foundation set of classes, but
in the appkit - now as I am building a command line utility when I used NSImage it failed with a
linker failure - something I have not seen before in Xcode.

So after several hours of struggling I posted a question on Mac Forums and when I got up this morning there
was a response that gave me the clue I was looking for ...

macforums

wonderful.

On the other hand there is a real danger that you start picking up code from other people and you don't really deeply know what you are doing -

Here for example I found someone who had the problems I had this morning - failing to resize an NSImage and then getting crashes

Great the answer is good and works for me -

cocoabuilder


But I don't really (deeply) know what he is doing. Sure at some superficial level it is clear he is drawing the old bitmap onto a new bitmap of the
right size but I have not put those lines of code together and read the manual on each of them so I am in danger of kidding myself
I know what I am doing!

Anyway here is my finished code for a command line utility to resize a jpeg image file.

blah


(Link for this specific entry...)

1 Nov 2008

Resizing a jpeg in Cocoa


If your image has an NSBitmapImageRep it's dead simple. Get the image
rep and send it


- (NSData *)representationUsingType:(NSBitmapImageFileType)
storageType properties:(NSDictionary *)properties.

The first argument can be one of (at least) NSBMPFileType,
NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType. Then
do what you like with the NSData you end up getting.

If you don't have a bitmap ImageRep, or don't care to go to the
effort to find out if you do, you can make one:


NSBitmapImageRep* bm = [NSBitmapImageRep imageRepWithData:[image
TIFFRepresentation]];

"'
===============================

How to Resize an NSImage


NSImage has a method called setSize, which the documentation says "sets the width and height of the image."

It seems like one should be able to simply read the data into the image, set its size, get the TIFF representation, and write that to disk.
Not so. As it turns out, setSize() only specifies how the image is displayed when it's drawn-it does nothing to the underlying data.
The most straightforward way to actually resize the data is to create another NSImage with the new size,
lock focus on it, draw the source image into the new image, and then get the TIFF representation of the new, scaled image.
This may be obvious to some, but it certainly wasn't to me,
and I had trouble finding illuminating examples or explanations through Google,
so I thought I'd post my code here to help anyone else who is similarly befuddled.
If anyone has anything interesting to add on the subject, do let us know in the comments…

NSData *sourceData ... // Get your data from a file, URL, etc.
float resizeWidth = 13.0;
float resizeHeight = 13.0;
NSImage *sourceImage = [[NSImage alloc] initWithData: sourceData];
NSImage *resizedImage = [[NSImage alloc] initWithSize: NSMakeSize(resizeWidth, resizeHeight)];
NSSize originalSize = [sourceImage size];
[resizedImage lockFocus];
[sourceImage drawInRect: NSMakeRect(0, 0, resizeWidth, resizeHeight) fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height) operation: NSCompositeSourceOver fraction: 1.0];
[resizedImage unlockFocus];
NSData *resizedData = [resizedImage TIFFRepresentation];
[sourceImage release];
[resizedImage release];



You can control the output a bit by throwing a [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolation{None, Low, High}]; in there after [resizeImage lockFocus].
More interpolation means more smoothness, less is closer to resampling. The default here seems to be low interpolation.
For something as small as a favicon you probably want low or none, I'd think, as it's going to look blurry with smoothing.
I did this a while ago in writing a little app to make thumbnail images for photographs. Then I found Pic2Icon..

Hm, it's an aesthetic issue, but I disagree with Ken - high interpolation looks good for small icons too.
In my current project I'm taking usericons, that are usually 64x64 or later, and resizing them down to 16x16 with good results using high interpolation.


Okay, I did a little test out of curiosity. High interpolation certainly looks a lot better than I guessed it would, and no interpolation is a clear loser on my test set.
I've been waffling on whether I prefer low or high interpolation, but right now I'm thinking high.
You can see the images at http://homepage.mac.com/kenferry/temp/FavIconsInterpolationTest.zip
The images are freshly downloaded favicons, resized to 13x13 pixels since that's what Buzz does above.
The favicons tested are those that are in my NetNewsWire cache, but I redownloaded them in case Brent messed with the images before he saved them (it looks like he didn't).
The holes in the grid indicate images that NSImage was unable to load. I don't know what's going on with that.


[NSImage setSize] can scale the image. All one has to do is to call [NSImage setScalesWhenResized: YES] first.]


Thanks for the test. I actually think that the high interpolation ones look pretty darn good, and I think I'll switch to using that method in Cocoalicious.


(Link for this specific entry...)

22 Oct 2008

More Apache Hassles


I want to include the vertical menus on my webside by server side includes -

using the <!-- #include --> directive - this however took me a little while to cope with.

Firstly there are two forms -


<!--#include file="somefile.html" -->
<!--#include virtual="someotherfile.html"-->


now file will strangely not resolve any file that isn't in or below the directory of the file that
it is currently being included from. i.e. fully enumerated paths and the '..' symbol won't work.

virtual on the other hand will include a file anywhere, but importantly starts at the 'document root directory'

In apache2 as included and installed in mac OSX 10.5.5 the document root is /Library/WebServer/Documents

which is different from the individual users Site home directory. which is in a directory something like -

  
/Users/someuser/Sites


As I don't want to host my website from that directory - i have to go back and change the apache
config file again - which regular readers may recall is hidden away in private/etc/apache2/httpd.conf

it turns out you need to change this to -


#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents"
and replace with the path to your sites folder, mine is "/Users/someuser/Sites"


Then find-


#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Library/WebServer/Documents">
And change there as well, e.g.

<Directory "/Users/someuser/Sites">


restarting apache2 is of course necessary to make it work....

\\localhost should change - but \\localhost wont find an index.shtml which is annoying.


(Link for this specific entry...)

11 Oct 2008

TRUE and FALSE, YES and NO


I have always had trouble remembering which way the boolean values map in C (1 = TRUE, 0 = FALSE )
Although TRUE and FALSE are not actually defined unless you do a type_def

Of course it is worth remembering that C treat evaluation of any non-zero result as true.

So if ( 100 ) do something; // will mean always do it. and...

if (! 100) do something; // will mean never do it.

So ok fair enough, but then in objective C we do have a BOOL type with YES and NO as values
but how exactly do the two interrelate and can you assume YES is the same as TRUE?


Another few hours struggling to find an issue with displaying CSS on Apache2

The blog pages currently use two cascading style sheets - and some of the styles were rendering
properly and others not. PearsonMain.css was not rendering but OMWB.css was rendering. After hours of
trying to find in something that was wrong with the PearsonMain.css file I had a look int he Apache2 log file

In Mac OS 10.5 (at least for me) this meant going into terminal using the cd command to get to var/log/apache2
and then using the tail command - tail access_log to see the apache access log.

I got the following.....


192.168.1.69 - - [11/Oct/2008:18:22:48 +0100] "GET /~tim/Car/Car-OMWB.shtml HTTP/1.1" 200 1191
192.168.1.69 - - [11/Oct/2008:18:22:48 +0100] "GET /~tim/images/achnag_from_the_air.jpg HTTP/1.1" 200 6527
192.168.1.69 - - [11/Oct/2008:18:22:48 +0100] "GET /~tim/OMWB.css HTTP/1.1" 200 398
192.168.1.69 - - [11/Oct/2008:18:22:48 +0100] "GET /~tim/PearsonMain.css HTTP/1.1" 403 222
192.168.1.69 - - [11/Oct/2008:18:22:48 +0100] "GET /favicon.ico HTTP/1.1" 404 209


which meant that the server wasn't even reading the missing css file?

Then I remembered something about access permissions and so I went to the directory and used the chmod command
to set ALL access permissions to the non-rendering css file - as shown below -

Tims-iMac:Sites tim$ chmod a+rwx PearsonMain.css
Tims-iMac:Sites tim$ ls -l
total 136
drwxr-xr-x 11 tim staff 374 11 Oct 18:15 Car
drwxr-xr-x 8 tim staff 272 11 Oct 10:48 Computing
-rw-r--r--@ 1 tim staff 398 11 Oct 18:08 OMWB.css
-rwxr-----@ 1 tim staff 1837 11 Oct 13:11 PearsonMain copy.css
-rwxrwxrwx@ 1 tim staff 1440 11 Oct 18:05 PearsonMain.css
-rw-r--r--@ 1 tim staff 1440 11 Oct 18:09 PearsonMain2.css
-rwxrwxrwx@ 1 tim staff 1466 5 Sep 18:59 family.css
-rwxrwxrwx 1 tim staff 1118 27 Apr 12:46 family_handheld.css
drwxrwxrwx 20 tim staff 680 8 Oct 10:08 images
-rwxrwxrwx@ 1 tim staff 2104 10 Oct 19:35 index.shtml
Tims-iMac:Sites tim$ <br />


And sure enough this solved the problem, and now the access_log file could be seen not nly getting the
css file but also the other files it references

Tims-iMac:apache2 tim$ tail access_log
192.168.1.69 - - [11/Oct/2008:18:52:54 +0100] "GET /~tim/Car/Car-OMWB.shtml HTTP/1.1" 200 1191
192.168.1.69 - - [11/Oct/2008:18:52:54 +0100] "GET /~tim/OMWB.css HTTP/1.1" 200 398
192.168.1.69 - - [11/Oct/2008:18:52:54 +0100] "GET /~tim/images/achnag_from_the_air.jpg HTTP/1.1" 200 6527
192.168.1.69 - - [11/Oct/2008:18:52:54 +0100] "GET /~tim/PearsonMain.css HTTP/1.1" 200 1440
192.168.1.69 - - [11/Oct/2008:18:52:54 +0100] "GET /favicon.ico HTTP/1.1" 404 209
192.168.1.69 - - [11/Oct/2008:18:52:54 +0100] "GET /~tim/images/header_fill_pic.jpg HTTP/1.1" 200 990
192.168.1.69 - - [11/Oct/2008:18:52:54 +0100] "GET /~tim/images/PFW_Title_Bar.jpg HTTP/1.1" 200 9843
Tims-iMac:apache2 tim$ <br />


IN fact I only needed to turn on the read permission for 'other permissions' so the following would have
done ....

Tims-iMac:Sites tim$ chmod o+r PearsonMain.css



Key learning point - if you are using Apache2 to serve your files then make sure it has the relevant file
permissions......It seems a strange Apple quirk that you have to swap from friendly GUI apps right down to
Unix commands to achieve this....surely there must be a better way (don't call me shirley).



(Link for this specific entry...)

10 Oct 2008

How to change the organization name in the objective C development environment


From Terminal


defaults write com.apple.xcode PBXCustomTemplateMacroDefinitions'{ ORGANIZATIONNAME = "Tim Pearson"; }'


To add a class in the objective C development environment

New file | choose template xcode from list on left | select objective-c class then finish




(Link for this specific entry...)

9 Oct 2008

Relatively little done today, I have tidied up some of the code, and I have made some alterations

to allow the output to be put in the right locations - so that it links to the main site home page.

This generated me a new problem, in that it was the first time I had run the blog output under apache.
(as opposed to just opening the file from the computer - see yesterday's post if this doesn't make sense)

Running under apache2 browsing from safari gave me a problem that only one of the two style sheets
loaded by the header to each page - seemed to be having any effect - so the pages are rendering
poorly.

You can see the difference looking at the same test pages below - they are exaclty the same bit of
html/css, not even copies the same files in the same place - it's just one is being served by apache
and one is being opened directly from the file system.

Here is it loaded with Apache -

some placeholder words for the tool tip

And here it is loaded as a straight file form the browser -

some placeholder words for the tool tip



argh

Other things to do -

1/ Multiple Blogs - the code is really designed only to do one blog at a time at the moment, as I eventually
want it to do all the blogs then I think I should fix this soon.

2/ jpgs/pngs/gifs etc. - it doesn't move them around or put the links in for them at all yet

3/ filling up the navigation bar

4/ testing it on an online system


(Link for this specific entry...)