I'm using extent in rmagick/imagemagick to center images on a canvas of certain size.
On some of my machines, it centers them - on others it does the opposite. If I fix code to work on one machine, it does the exact opposite on the other.
Does anyone know why this is happening?
I actually already knew the answer -- after 5 hours of struggling with code. Just posting this for reference.
For some unknown (and I think stupid) reason , this appeared in the ImageMagick changelog:
2010-09-13 6.6.4-2 Cristy <quetzlzacatenango@image...>
# Don't negate the geometry offset for the -extent option.
For whatever reason, the ImageMagick team decided it was okay to change a function to do LITERALLY THE EXACT OPPOSITE OF WHAT IT HAS HISTORICALLY DONE in a release .
The function should have remained as-is, a corollary function with the new behavior could have been introduced, and the original function been deprecated - with warnings - over several releases.
A strategy such as this - which is pretty much the standard way of handling changes like this - would have allowed those with active code built against ImageMagick to continue as normal. Instead, people now have to write code supporting both versions of this function, or forcing upgrades.
the following ruby code is an example of how to handle this, as you have NO IDEA WHATSOEVER what version someone will be running on their machine.
offset_coords= { 'x' => 100 , 'y' => 100 }
expects_negated = true
# ImageMagick 6.6.4-2 changed the behavior of extent
# me: !(*@&#(#! .
#mversion = "ImageMagick 6.6.4-1 2010-12-07 Q16 http://www.imagemagick.org"
mversion = Magick::Magick_version
( v_version , v_commit ) = mversion.split(' ')[1].split('-')
( v_version_1 , v_version_2 , v_version_3 ) = v_version.split('.')
if Integer(v_version_1) >= 6 and Integer(v_version_2) >= 6 and Integer(v_version_3) >= 4 and Integer(v_commit) >= 2
expects_negated= false
end
if expects_negated
offset_coords['x'] = - offset_coords['x']
offset_coords['y'] = - offset_coords['y']
end
@new_image.background_color= "#000000"
@new_image = @new_image.extent( target_dimensions['w'] , target_dimensions['h'] , offset_coords['x'] , offset_coords['y'] )