Image sharing in Online Social Networks (OSNs) faces potential risks of exposing users' private or sensitive information to others. In this paper, we develop a framework of calculating the privacy level of a digital image based on perceptual hashing and semantic privacy rules. In particular, we design two privacy preserving perception hashing methods: the first one is based on the SIFT features which focus on the description of sensitive objects in the image and the second one is based on the LBP features which focus on the description of faces in the image. Both methods use the secret key to protect hashes from adversaries or untrusted servers. The recommendation of a privacy level for a given image is based on two types of privacy rules, user-defined specific rules based on the logic combination of the semantic tags of image objects retrieved from the perceptual hash database, and general rules based on machine learning. The privacy level, as the measurement of the degree of sensitivity of a digital image, can be directly fed to the user before he shares the image to OSNs. It can also be fed to the user's access control component. Experimental results show the effectiveness and usability of the proposed framework.