A pinhole doesn't act like a lens, as is often written.
A pinhole is more like a filter, than it is a lens.
Let's say you have a diamond ring.
There a many rays of light reflecting off of the ring in every direction.
One can think of the surface of the diamond ring as being covered with many garden sprayers.
Each of these garden sprayers is spewing out light drops in every direction.
Now, let's say you place a cardboard box in front of the diamond ring.
You cut a three-inch hole in the box.
The innumerable light drops emanating from the sprayers on the diamond ring go through the three-inch hole in the box.
If you could stand inside the box, the back of the box would be bright.
But, there would be no image of the diamond ring on the inside back of the box.
When the innumerable light drops reach the back of the box, they flow, blur, together.
Next, you place a pinhole over the three-inch hole in the box.
The tiny opening of the pinhole blocks, filters, most of the innumerable light drops emanating in every direction from the sprayers.
If you could stand inside the box, you would see an image of the diamond ring on the back of the box.
The light reaching the back of the box is dim, because the pinhole is filtering out most of the rays of light.
So, long exposures are needed with pinhole cameras.
Let's say you have a diamond ring and a lens.
There are many rays of light reflecting off of the diamond ring.
These rays of light reach the front surface of the lens.
When the light rays go through the glass of the lens, they slow down.
The light rays change direction.
This is called refraction.
The shape of the lens controls the direction of the light rays.
For example, they can be made to focus, producing an image of the diamond ring.