2

I have the following image ontop of an image that is exactly 424x318

my image

And it is wrapped in a div that is 444x338.

And I have a "cropping tool" (the circle center piece) that is 185x185, BUT can resize to be a minimum of 50x50 and a max of about 300x300 (depending on placement).

The cropping tool has a top "border/margin" of 28 px and a left "border/margin" of 20pixels (these are the measurements that take up the tabs, and purple lines and white stuff. However it can be resized, which would increase the border/margin by the resize percentage (so if the entire thing goes to 1.5, the scale would be *1.5).

The cropping tool is also 185x185 WxH total.

The standard position is the center (which is 66x120).

Okay now that we got all those out of the way, I am having a problem trying to find the center & one point that I pass onto imagemagick to process. I currently have the following

// Get variables
$left = $val->pos['0']; // this is posted from jquery, using position();
$top = $val->pos['1']; // this is posted from jquery, using position();
$scale = $val->scale; // this is posted from jquery, using width/185

$img = $val->image; // background image
$h = $scale*185;


// CENTER OF THE CIRCLE
$c1 = ($h*.5)+$left-20;
$c2 = ($h*.5)+$top-10;

// LEFT SIDE
$c3 = $left+(20*$scale)-10;
$c4 = ($h*.5)+$top-10;

$scalesize = $c1.",".$c2." ".$c3.",".$c4;

// Crop Size WxH+X+Y
$cr1 = $h-(40*$scale)-17;
$cr2 = $h-(40*$scale)-14;

$cr3 = $left-(20*$scale)+28;
$cr4 = $top+(20*$scale)-3;

$cropsize = $cr1."x".$cr2."+".$cr3."+".$cr4;

I then pass it onto imagemagick using

$return = exec('convert -size 424x318 xc:none -fill 'filename' -draw "circle '.$scalesize.'" -crop '.$cropsize.' +repage '.newfilename);

I just cannot for the life of me figure out what I am doing wrong. I keep playing with the ##'s that I am subtracting at the end, and it ends up working for one size, but then when I resize the crop tool it messes it all up... Any help?

casperOne
  • 73,706
  • 19
  • 184
  • 253
Steven
  • 13,250
  • 33
  • 95
  • 147

2 Answers2

0

Try to do one step at a time:

  1. Ensure that your tool crops in the right place (use this: Crop or mask an image into a circle);
  2. Ensure that resize (only) works fine;
  3. Merge those two parts.
Community
  • 1
  • 1
jrumbinas
  • 426
  • 3
  • 19
0

If the margin resizes with the scale, then you must scale your constants accordingly.

Something like this:

// CENTER OF THE CIRCLE
$c1 = ($h*.5)+$left-20 * scalesize;  // Apply scale to constant
$c2 = ($h*.5)+$top-10 * scalesize;  // Apply scale to constant
Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82