Every person sentenced to imprisonment in any such city or town, either directly or in consequence of a failure to pay a fine imposed, shall be subject to work upon the public roads of such city or town of over one thousand inhabitants or of the county in which such city or town is situate during the term of such imprisonment.