the code looks correct, How are you verifying that the width is not changing?
Are you examining the files directly on the server? or are you looking at the image in a web page? If you are looking at the image in a web page, it could be that the image tag has a height or width attribute set that is overriding the actual file width.