/ Published in: PHP

This code war written for a project I'm working on where a map of the world may need to be offset to center the view on specific areas. I'm also using it as a part of an iterative blur function to prevent seams from the blur operation.
I would like to eventually tweak the function to receive both X & Y values for the offset command, but am a tad lazy right now on this fine Sunday afternoon.
I would like to eventually tweak the function to receive both X & Y values for the offset command, but am a tad lazy right now on this fine Sunday afternoon.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function image_offset_x($image, $offset){ // Values too large need to be modded. // (this is my first use of %mod that doesn't have to do with alternating table rows.) $offset = $offset % $width; } // Negative values need to be handled differently. if($offset < 0){ $offset = $width + $offset; } // Do nothing for zero offset values. if($offset == 0){ return $image; } $chunk1_w = $offset; $chunk1_h = $height; $chunk1_xs = $width - $offset; $chunk1_ys = 0; $chunk1_xd = 0; $chunk1_yd = 0; $chunk2_w = $width - $offset; $chunk2_h = $height; $chunk2_xs = 0; $chunk2_ys = 0; $chunk2_xd = $offset; $chunk2_yd = 0; // Copy first chunk // Copy second chunk return $new_image; }
Comments
