{"action":"created","issue":{"url":"https://api.github.com/repos/jcupitt/libvips/issues/491","repository_url":"https://api.github.com/repos/jcupitt/libvips","labels_url":"https://api.github.com/repos/jcupitt/libvips/issues/491/labels{/name}","comments_url":"https://api.github.com/repos/jcupitt/libvips/issues/491/comments","events_url":"https://api.github.com/repos/jcupitt/libvips/issues/491/events","html_url":"https://github.com/jcupitt/libvips/issues/491","id":167179056,"number":491,"title":"experiment with round to nearest for image size change","user":{"login":"jcupitt","id":580843,"avatar_url":"https://avatars.githubusercontent.com/u/580843?v=3","gravatar_id":"","url":"https://api.github.com/users/jcupitt","html_url":"https://github.com/jcupitt","followers_url":"https://api.github.com/users/jcupitt/followers","following_url":"https://api.github.com/users/jcupitt/following{/other_user}","gists_url":"https://api.github.com/users/jcupitt/gists{/gist_id}","starred_url":"https://api.github.com/users/jcupitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcupitt/subscriptions","organizations_url":"https://api.github.com/users/jcupitt/orgs","repos_url":"https://api.github.com/users/jcupitt/repos","events_url":"https://api.github.com/users/jcupitt/events{/privacy}","received_events_url":"https://api.github.com/users/jcupitt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jcupitt/libvips/labels/enhancement","name":"enhancement","color":"0b02e1"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/jcupitt/libvips/milestones/2","html_url":"https://github.com/jcupitt/libvips/milestones/8.4","labels_url":"https://api.github.com/repos/jcupitt/libvips/milestones/2/labels","id":1762409,"number":2,"title":"8.4","description":null,"creator":{"login":"jcupitt","id":580843,"avatar_url":"https://avatars.githubusercontent.com/u/580843?v=3","gravatar_id":"","url":"https://api.github.com/users/jcupitt","html_url":"https://github.com/jcupitt","followers_url":"https://api.github.com/users/jcupitt/followers","following_url":"https://api.github.com/users/jcupitt/following{/other_user}","gists_url":"https://api.github.com/users/jcupitt/gists{/gist_id}","starred_url":"https://api.github.com/users/jcupitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcupitt/subscriptions","organizations_url":"https://api.github.com/users/jcupitt/orgs","repos_url":"https://api.github.com/users/jcupitt/repos","events_url":"https://api.github.com/users/jcupitt/events{/privacy}","received_events_url":"https://api.github.com/users/jcupitt/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":6,"state":"open","created_at":"2016-05-12T13:27:03Z","updated_at":"2016-08-18T13:41:20Z","due_on":null,"closed_at":null},"comments":22,"created_at":"2016-07-23T10:47:06Z","updated_at":"2016-08-19T11:18:16Z","closed_at":null,"body":"vips always does int() on image dimensions for a size change. The aim is to prevent fractional pixels at image edges.  If you want to size to a specific number of pixels, you need to add a small positive offset to the target size to prevent rounding errors producing a smaller image than you wanted.\r\n\r\nThis seems ugly. Investigate switching to round to nearest rather than strict round down. This will affect at least resize, affine, reduce, reduceh, reducev, shrink. \r\n\r\nSee https://github.com/jcupitt/libvips/pull/490\r\n"},"comment":{"url":"https://api.github.com/repos/jcupitt/libvips/issues/comments/240992756","html_url":"https://github.com/jcupitt/libvips/issues/491#issuecomment-240992756","issue_url":"https://api.github.com/repos/jcupitt/libvips/issues/491","id":240992756,"user":{"login":"felixbuenemann","id":909587,"avatar_url":"https://avatars.githubusercontent.com/u/909587?v=3","gravatar_id":"","url":"https://api.github.com/users/felixbuenemann","html_url":"https://github.com/felixbuenemann","followers_url":"https://api.github.com/users/felixbuenemann/followers","following_url":"https://api.github.com/users/felixbuenemann/following{/other_user}","gists_url":"https://api.github.com/users/felixbuenemann/gists{/gist_id}","starred_url":"https://api.github.com/users/felixbuenemann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixbuenemann/subscriptions","organizations_url":"https://api.github.com/users/felixbuenemann/orgs","repos_url":"https://api.github.com/users/felixbuenemann/repos","events_url":"https://api.github.com/users/felixbuenemann/events{/privacy}","received_events_url":"https://api.github.com/users/felixbuenemann/received_events","type":"User","site_admin":false},"created_at":"2016-08-19T11:18:16Z","updated_at":"2016-08-19T11:18:16Z","body":"> @felixbuenemann because it's now round-to-nearest, you have a 0.5 margin of error, so it doesn't matter.\r\n```\r\nscale = target_width.to_f / original_width\r\n```\r\nAnd it'll be correct.\r\n\r\nExcept it isn't correct, as the discussion above shows, that `resize()` rounds down in cases where it should round up, so I need to have some additional logic to determine when that happens.\r\n\r\nYour commit showed a similar issue:\r\n\r\n```ruby\r\n1450 * 0.33\r\n=> 478.5\r\nx = Vips::Image.black(1450, 1450)\r\ny = x.resize(0.33)\r\ny.width\r\n=> 478 # expected 479\r\n```\r\n\r\nSo apparently `resize()` always rounds down for 0.5 when it should round up.\r\n\r\nRegarding the round to zero case: As long as the rounding is predictable, I think the exception is ok."}}
{"actor":{"display_login":"felixbuenemann"}}