i am working on a website where i select some imported images to flip them for display. i do that to have all objects on the images to face in the same direction. i use flags to select some images and then use a different image cache preset. blahblahblah. anyhow, i use this custom code in a imagecache action. might be usefull for some ppl. credit goes to this website, were i adopted the code from:
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=1876&l...

i have both vertically and horizontally flips in the code, so you need to comment out what you do not need:

here goes:

$size_x = imagesx($image->resource);
$size_y = imagesy($image->resource);
$temp = imagecreatetruecolor($size_x, $size_y);

//use this line to flip image vertically (upside-down)
//$x = imagecopyresampled($temp, $image->resource, 0, 0, 0, ($size_y-1), $size_x, $size_y, $size_x, 0-$size_y);

//use this line to flip image horizontally (right-left)
$x = imagecopyresampled($temp, $image->resource, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y);

if ($x) {
    $image->resource = $temp;
}

Comments

fietserwin’s picture

Version: 6.x-1.6 » 7.x-1.x-dev
Component: Custom Actions Module » Code
Category: task » feature

[A late reply, but we are going through the issue queue now.]

Looks like a nice addition, not too difficult either. But we will not do so anymore for D6. For D7, I would be fine with adding it. A few questions though:
- Can you flip both horizontally and vertically at the same time (equals a rotation of 180 degrees, but could still be useful via this effect)?
- Can you provide an imagemagick implementation (or at least a start of it)?

If you can provide us with a complete working effect, you will of course be properly attributed. If you would like to try, don't bother creating a full separate sub module for it, we are going through the effect grouping anyway,so just 1 file that handles all the hooks, callbacks, and theme functions.

dman’s picture

Due to the rarity of demand for this exact effect, I dunno if it's worth the code cost as another option to the list.
However it is a really good example of a short custom_action that someone may want to build on!

I'd nominate that this goes into documentation for customactions, either instead of or as well as the current 'wavy' filter that's currently there for copy & paste. Perhaps we could get a few customactions snippets together. I'd rather "teach a man to fish" with custom actions than to overload the UI with options that would be used 1/10000 of the time. We'll never be able to anticipate every want, and building on customactions means that unique support requests can be hashed out in the issue queue instead of as feature requests.
At least, that's how I've been approaching a few support requests where the UI build cost is bigger than the 3-line custom_action that actually solves the task.

Just a thought.

Greg Sims’s picture

We have a website that promotes an image to the home page or the site. The position on the home page is on the right side of the page. The position of the image on the original page is on the left. The availability of a horizontal flip function allows images of people to always face towards the middle of the page -- it is very distracting when the image of a person is looking off the page.

I suggest this use case is fairly common. It happens in my experience on a regular basis.

And now, back to building a custom_action for this use case.

proweb.ua’s picture

Issue summary: View changes

for GD
imageflip($image->resource, IMG_FLIP_HORIZONTAL);
or
imageflip($image->resource, IMG_FLIP_VERTICAL);

fietserwin’s picture

I wouldn't care depending on php5.5+ for a specific effect. So, if someone posts a complete and working patch I will commit it. But please note that a complete patch should include imagick support as well.