<?php include 'concha.php';
require_once('imageworkshop.php');
$imagen_original = $_GET['i'];

function calculAngleBtwHypoAndLeftSide($bottomSideWidth, $leftSideWidth)
{
    $hypothenuse = sqrt(pow($bottomSideWidth, 2) + pow($leftSideWidth, 2));
    $bottomRightAngle = acos($bottomSideWidth / $hypothenuse) + 180 / pi();
     
    return -round(90 - $bottomRightAngle);
}
 
$norwayLayer = new ImageWorkshop(array(
    "imageFromPath" => "$imagen_original",
));
 
$textLayer = new ImageWorkshop(array(
    "text" => "$marca_de_agua",
    "fontPath" => "arial.ttf",
    "fontSize" => 40,
    "fontColor" => "000000",
    "textRotation" => calculAngleBtwHypoAndLeftSide($norwayLayer->getWidth(), $norwayLayer->getHeight()),
));
 
// Some funky opacity
$textLayer->opacity(70);
 
// We add the $textLayer on the norway layer, in its middle
$norwayLayer->addLayer(1, $textLayer, 0, 0, 'MM');
 
$image = $norwayLayer->getResult();
header('Content-type: image/jpeg');
 
imagejpeg($image, null, 95);