Updated compressImage method