-
Hello Is it possible for smartcrop achieve the same that jquery focuspoint does? From what I can read in the docs, smartcrop has a few pre-defined constants but I would like to know if it is possible to provide a center point on the image and smartcrop outputs coordinates for me to use in the crop with the dimensions I want. This way, my users can define their point of interest in the image and have a resulting image of Wpx x Hpx centered around that particular point. Best regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @jarodium,
|
Beta Was this translation helpful? Give feedback.
-
Hello again For anyone who is trying to merge Jquery Focus Point coordinates to make a crop here is a rough simple solution: function coordToOffset(float $coord): float {
//Takes a Jquery Focus Point coordinate into an offset
return ($coord + 1) * 0.5;
}
//this assumes the original image was 1420x1920 and we thumbnailed it to 320 width.
$imageWidth = 320;
$imageHeight = 433;
//I want an image with these dimensions
$finalWidth = 320;
$finalHeight = 230;
$focusPointY = -0.28;
$Y = min(1, max(-1, $focusPointY));
//convert $Y coordinate to an offset in % ( this is gives a % from the top. Remove 100- and you will end up with a % from the bottom )
$yPer = 100-intval(round(coordToOffset($Y) * 100));
//determine where we should we start to crop in Y axis ( X axis is always zero in my use case )
$yPosStart = round(($imageHeight * $yPer) / 100,0);
//determine where will the crop area will end
$yPosEnd = $yPosStart + $finalHeight;
$yDist = 0;
//if $yPosEnd does exceed the height of the image ( 433 )
if ($yPosEnd > $imageHeight) {
//we will check the difference between $yPosEnd and $imageHeight
$yDist = $yPosEnd - imageHeight;
//with this value in hand we will push $YposStart more to the top
$yPosStart -= $yDist;
}
$vips->crop(0,$yPosStart,$finalWidth,$finalHeight); This is a rough sketch of the function i am working with. It does lack some aditional checks to avoid $yPostStart to go out of bounds on the top and it requires previous knowlegde of the end image dimensions. Also, I am always aware of the image sizes since I'm using this in a CMS i am working on, so the designers ( aka master's of the graphicverse xD ) will always be able to provide specific sizes for specific goals, so that is not an issue. X axis is not accountable for my use case, but one can make the same calculations with safety. Best regards to all |
Beta Was this translation helpful? Give feedback.
Hi @jarodium,
smartcrop
attempts to position the reticule automatically. If you want to set the position yourself, I would thumbnail the whole image, then crop afterwards. So ... setcrop
tonone
(the default), then crop the output yourself.