Positioned croped images in CP "images <div>"

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
metti
Posts: 81
Joined: Tue 28. Nov 2006, 07:34
Location: Merseburg
Contact:

Positioned croped images in CP "images <div>"

Post by metti »

Hi out there!

Today i found out, that since release "snapshot 2007-10-12" (1.3.5) it's possible to crop images in the Contentpart "images <div>".

I was really happy about that (Thanx Oli) but missed a feature, that would make this functionality a bit more fiting for me:
To tell phpwcms how much of the image should be croped

So i looked up the code, made some changes and got it to work:

After changing 3 things in 2 files of the core it is possible to use this RP-Tag in the caption of each image:

{POS:x:y}
(x and y are the pixels that are croped on the image and also may be "center")

In the Frontend it looks like this:
http://www.netzelf.de/index.php?aid=3&pg=3

In the Backend it looks like this:
Image

So what is to do to get this working?

Open include/inc_lib/imagick.convert.inc.php and find:

Code: Select all

$default = array(
              		"max_width"		=>	$GLOBALS['phpwcms']["img_list_width"],
              		"max_height"	=>	$GLOBALS['phpwcms']["img_list_height"],
              		"image_dir"		=>	PHPWCMS_ROOT . '/' . PHPWCMS_FILES,
              		"thumb_dir"		=>	PHPWCMS_ROOT . '/' . PHPWCMS_IMAGES,
              		'jpg_quality'	=>	$GLOBALS['phpwcms']['jpg_quality'],
              		'sharpen_level'	=>	$GLOBALS['phpwcms']['sharpen_level'],
              		'crop_image'	=>	false
After this (after line 257) add the following:

Code: Select all

                      ,
              		'crop_x'  => false, //Added for positioned croping
              		'crop_y'  => false  //Added for positioned croping
Then find

Code: Select all

        $crop_x = abs( $image->get_w() - $imagick["max_width"] );
				$crop_x = ceil( $crop_x / 2 );
				$crop_y = abs( $image->get_h() - $imagick["max_height"] );
				$crop_y = ceil( $crop_y / 2 );
and add after this (line 209):

Code: Select all

			  //Added for positioned croping
        if ($imagick['crop_x'] != false && $imagick['crop_y'] != false) {
          $crop_x = ($imagick['crop_x'] != "center") ? $imagick['crop_x'] : $crop_x;
          $crop_y = ($imagick['crop_y'] != "center") ? $imagick['crop_y'] : $crop_y;
        }
        //End of Changes for positioned croping
Open include/inc_front/content/cnt29.article.inc.php and replace

Code: Select all

        $thumb_image = get_cached_image(
						array(	"target_ext"	=>	$image['images'][$key][3],
								"image_name"	=>	$image['images'][$key][2] . '.' . $image['images'][$key][3],
								"max_width"		=>	$image['images'][$key][4],
								"max_height"	=>	$image['images'][$key][5],
								"thumb_name"	=>	md5(	$image['images'][$key][2].$image['images'][$key][4].
															$image['images'][$key][5].$phpwcms["sharpen_level"].
															$image['crop']
														),
								'crop_image'	=>	$image['crop']
        					  )
						);
(line 127 to line 138) with

Code: Select all

			 //Add position for croping images (by netzelf)
      $img_thumb_vars = array(	"target_ext"	=>	$image['images'][$key][3],
								"image_name"	=>	$image['images'][$key][2] . '.' . $image['images'][$key][3],
								"max_width"		=>	$image['images'][$key][4],
								"max_height"	=>	$image['images'][$key][5],
								"thumb_name"	=>	md5(	$image['images'][$key][2].$image['images'][$key][4].
															$image['images'][$key][5].$phpwcms["sharpen_level"].
															$image['crop']
														),
								'crop_image'	=>	$image['crop']  );
      preg_match('/\{POS:(.+?):(.+?)\}/is', $image['images'][$key][6], $img_pos);
      $image['images'][$key][6] = preg_replace('/\{POS:(.+?):(.+?)\}/is', "", $image['images'][$key][6]);
      if (!empty($img_pos[1]) && !empty($img_pos[2])) { 
        $img_thumb_vars["crop_x"] = $img_pos[1];
        $img_thumb_vars["crop_y"] = $img_pos[2];
        $img_thumb_vars["thumb_name"] = md5(	$image['images'][$key][2].$image['images'][$key][4].
															$image['images'][$key][5].$phpwcms["sharpen_level"].
															$image['crop'].$img_pos[1].$img_pos[2]
														);
      }   
      
			$thumb_image = get_cached_image($img_thumb_vars);
      //End of changes for positioned croping
Ready

Hope you will like this as much as me :D
#GeorgeWBush { position:absolute; bottom:-6ft; }
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

very nice

Post by jsw_nz »

such an approach has crossed my mind
-so kudo's to you

excellent contribution - extends the concept
i am sure OliG will respond to this

big thanks metti
:)

one question however
does this (exclusively) require imagick to work ?
User avatar
metti
Posts: 81
Joined: Tue 28. Nov 2006, 07:34
Location: Merseburg
Contact:

Post by metti »

you're welcome :)

no. it works fine with GD. I did not test, if it also works with imagemagick but normaly it should.
#GeorgeWBush { position:absolute; bottom:-6ft; }
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Just incorporated your code adjustments
WORKS like a charm - nice! :)
User avatar
metti
Posts: 81
Joined: Tue 28. Nov 2006, 07:34
Location: Merseburg
Contact:

Post by metti »

:) Nice, that it suits you.

There is one feature this hack is in my oppinion missing:

At the moment OliG's Script always sizes the image to the value you specified for "max. width" in the Backend even if you chose cropping.

I think, that it would be also usefull to make sizing of the image users choice. So i will develop the tag to something like
{POS:crop_x:crop_y:width_x:width_y}
as soon as my freetime allows.
#GeorgeWBush { position:absolute; bottom:-6ft; }
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

- Not to add to the confusion
- but seeing that OliG has released a new CP: special images
- the thought crossed my mind of how your approach could
- benefit this new additional CP: (still in development)
- http://www.phpwcms.de/forum/viewtopic.php?t=16233

great work metti

Image
User avatar
metti
Posts: 81
Joined: Tue 28. Nov 2006, 07:34
Location: Merseburg
Contact:

Post by metti »

Thanx jsw_nz!
This was new for me but sounds great.

Would be realy fine, if the crop-thing was integrated to this CP.
#GeorgeWBush { position:absolute; bottom:-6ft; }
User avatar
Jensensen
Posts: 3000
Joined: Tue 17. Oct 2006, 21:11
Location: auf der mlauer

Re: Positioned croped images in CP "images <div>"

Post by Jensensen »

Hi metti,

Du netzcrack, bist Du eigentlich "halb und halb"?
Äh, was ich eigentlich sagen wollte: --> Kumma da: http://forum.phpwcms.org/viewtopic.php?f=16&t=20177
{so_much} | Knick-Knack. | GitHub
Umlaute im URL sind meistens immer Kacke.
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Re: Positioned croped images in CP "images <div>"

Post by jsw_nz »

Thanks Jens for trying
- seems you had mixed results

- i looked over the newest version of imagick.convert.inc
- seeing it has changed a bit.

Still would be a nice feature if Oliver could incorporate into the core
- might make a feature request.

cheers
:D

UPDATE: submitted as a feature request.
Last edited by jsw_nz on Sun 30. May 2010, 08:32, edited 1 time in total.
User avatar
metti
Posts: 81
Joined: Tue 28. Nov 2006, 07:34
Location: Merseburg
Contact:

Re: Positioned croped images in CP "images <div>"

Post by metti »

@jensensen - sorry, what?

Hi,

You are right: cropping images with gd2 is not possible. Well there is no special command for it. But what about taking an empty image with the dimensions to that the original image should get cropped and copying the latter into the empty image? What happens, is that the image will be cropped. That's as far as i remember the way Olivers script and my modifications did it.

I did not use phpwcms since 1.3.9 - so it's perhaps better to contact Oliver for support as he is the developer - is he still the only one?

Cheers,
metti
#GeorgeWBush { position:absolute; bottom:-6ft; }
NavegarEhPreciso
Posts: 1
Joined: Tue 11. Sep 2012, 19:53

Re: Positioned croped images in CP "images <div>"

Post by NavegarEhPreciso »

Hi
The hacker described above at 'Positioned croped images in CP "images <div>"'
Was working fine before version 1.5.4.1.
At this version 1.5.4.1 was not possible made the changes, because the file include/inc_lib/imagick.convert.inc.php it's now different .
Are there some other functionality that replaces that hacker?
I need crop the thumbnails, some at top of the image, others at the bottom.
Regards
User avatar
Oliver Georgi
Site Admin
Posts: 9888
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Positioned croped images in CP "images <div>"

Post by Oliver Georgi »

autocropping still uses the centered method. Might be possible to implement something to handle manual attributes. But have no clue right now before having a built-in cropping tool
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Post Reply