All pastes #900523 Raw Edit

Something

public php v1 · immutable
·published 2008-02-11 23:35 UTC
rendered paste body
<?phperror_reporting(E_STRICT);$relativeGraphicsPath = "../";$mConnection = mysql_pconnect("localhost", "asdfasdf", "neztset");if(!$mConnection){    die ('DB Connection Error');}$db_selected = mysql_select_db("asdfasdf", $mConnection);if (!$db_selected){    die ('DB Select Error');}set_time_limit(300);$sQuery = "select dj.ID, dj.BACKGROUNDCOLOR, dj.ITEMID, dj.FACEID, dj.INFOLAYERPATH, dj.COLLECTIONPATH, dj.SCALE, dp.FINALWIDTH, dp.FINALHEIGHT	from design_job dj	join design_products dp on dj.ITEMID = dp.PRODUCTSID and dj.FACEID = dp.FACEID	join orders_products_attributes opa on dj.COLLECTIONPATH = opa.products_options_values	where PROCESSED = false	LIMIT 1";$resultJobList = mysql_query($sQuery, $mConnection);    $cycleStart = time();    while ($aJob = mysql_fetch_array($resultJobList)) {    processImage($aJob);    $sQuery = "update design_job        set PROCESSED = TRUE        WHERE ID = '".$aJob['ID']."' ";	    mysql_query($sQuery, $mConnection);    }    $cycleEnd = time();    error_log("Process Complete: ".($cycleEnd - $cycleStart)." seconds.", 0);function processImage($aJob) {    global $mConnection;    global $relativeGraphicsPath;        $jobId = $aJob['ID'];    $bgrColor = $aJob['BACKGROUNDCOLOR'];    $itemId = $aJob['ITEMID'];    $faceId = $aJob['FACEID'];    $infoLayerPath = $aJob['INFOLAYERPATH'];    $name = $aJob['COLLECTIONPATH'];    $scale = $aJob['SCALE'];    $bgrWidth = $aJob['FINALWIDTH'];    $bgrHeight = $aJob['FINALHEIGHT'];    $tempFile = "/tmp/".$name.".png";    $finalFileName = "graphics/exports/full/$name";            error_log("Scale: ".$scale, 0);    error_log("Final Width: ".$bgrWidth, 0);    error_log("Final Height: ".$bgrHeight, 0);        $infoLayer = $relativeGraphicsPath.str_ireplace("/thumb/", "/full/",$infoLayerPath);            $tempBackground = imagecreatetruecolor($bgrWidth,$bgrHeight);    imagefill($tempBackground,0,0,$bgrColor);    imagepng($tempBackground, $tempFile);        $background = NewMagickWand();    MagickReadImage($background, $tempFile);    unlink($tempFile);    MagickSetImageUnits($background, MW_PixelsPerInchResolution);    MagickSetImageResolution($background, 300 , 300);            //MagickWriteImage($background, "/web/zenstaging/graphics/exports/full/test/back.png");        $sQuery = "select ID, DESIGNJOBID, IMAGEPATH, ALPHA, ROTATION, X, Y, SX, SY, FWIDTH, FHEIGHT 	    from design_job_items	    where DESIGNJOBID = '{$jobId}'";	        $resultJobItemsList = mysql_query($sQuery, $mConnection);        $count = 0;    while ($aJobItem = mysql_fetch_array($resultJobItemsList)) {        $count++;        $file = $relativeGraphicsPath.str_ireplace("/thumb/", "/full/", $aJobItem['IMAGEPATH']);        $alpha = $aJobItem['ALPHA'];        $rotation = $aJobItem['ROTATION'];        $x = $aJobItem['X'] * $scale;        $y = $aJobItem['Y'] * $scale;        $sx = $aJobItem['SX'];        $sy = $aJobItem['SY'];        $fWidth = $aJobItem['FWIDTH'] * $scale;        $fHeight = $aJobItem['FHEIGHT'] * $scale;                $wnd = NewMagickWand();        MagickReadImage($wnd, $file);        $transparentColor = NewPixelWand("none");                //MagickWriteImage($wnd, "/web/zenstaging/graphics/exports/full/test/wndPreRotate-".$count.".png");                $imageWidth = MagickGetImageWidth($wnd);        $imageHeight = MagickGetImageHeight($wnd);        error_log("imageWidth: ". $imageWidth, 0);        error_log("imageHeight: ". $imageHeight, 0);                    if ($rotation != 0) {                        error_log("sx: ". $sx, 0);            error_log("sy: ". $sy, 0);                        if ($sx != $sy) {                if ($imageWidth * $sx > $imageHeight * $sy) {                    $sy = ($sy / $sx);                    $sx = 1;                    error_log("X Is normal", 0);                } else if ($imageWidth * $sx < $imageHeight * $sy){                    $sx = ($sx / $sy);                    $sx = 1;                                    error_log("Y Is normal", 0);                } else {                    $sx = 1;                    $sy = 1;                      error_log("Both are normal", 0);                 }                MagickResizeImage($wnd, ($sx * $imageWidth), ($sy * $imageHeight), MW_CubicFilter, 0.5);             } else {                error_log("SX == SY", 0);             }            /*                        $hype = sqrt(($fWidth * $fWidth) + ($fHeight * $fHeight));            if ($imageWidth > $imageHeight) {                $aspectRatio = ($sx * $imageWidth) / $hype;            } else {                $aspectRatio = ($sx * $imageHeight) / $hype;            }                        $newAspectWidth = ($sx * $imageWidth) / $aspectRatio;            $newAspectHeight = ($sx * $imageHeight) / $aspectRatio;            error_log("Start Aspect Resize", 0);            MagickResizeImage($wnd, $newAspectWidth, $newAspectHeight, MW_CubicFilter, 0.5);             error_log("End Aspect Resize", 0);  */                      error_log("Aspect Image Width: ". MagickGetImageWidth($wnd), 0);            error_log("Aspect Image Height: ". MagickGetImageHeight($wnd), 0);                        error_log("Starting Rotation: ".$rotation, 0);            MagickRotateImage($wnd, $transparentColor, $rotation);            error_log("Ending Rotation", 0);                        error_log("Rotated Image Width: ". MagickGetImageWidth($wnd), 0);            error_log("Rotated Image Height: ". MagickGetImageHeight($wnd), 0);                    }                                if($x<0){            $mergeWidth = $fWidth+$x;            $dx = 0;            $sx = -$x;        }else{            $mergeWidth = $fWidth;            $dx = $x;            $sx = 0;        }        if($y<0){            $mergeHeight = $fHeight+$y;            $dy = 0;            $sy = -$y;        }else{            $mergeHeight = $fHeight;            $dy = $y;            $sy = 0;        }                        error_log("Processing: ".$file, 0);        error_log("SX: ".$sx, 0);        error_log("SY: ".$sy, 0);        error_log("DX: ".$dx, 0);        error_log("DY: ".$dy, 0);        error_log("fWidth: ".$fWidth, 0);        error_log("fHeight: ".$fHeight, 0);        error_log("alpha: ".$alpha, 0);        error_log("mergeWidth: ".$mergeWidth, 0);        error_log("mergeHeight: ".$mergeHeight, 0);        error_log("rotation: ".$rotation, 0);        error_log("Starting Resize", 0);                $blur = 0.3;        $resizeRatio = (($fWidth + $fHeight) / 2) / (($imageWidth + $imageHeight / 2));                                if ($resizeRatio > 2) {            //If the image is much bigger...            $blur = .7;        } else if ($resizeRatio < 2 && $resizeRatio > 1) {            $blur = .5;           }        error_log("resizeRatio: ".$resizeRatio, 0);        error_log("Blur: ".$blur, 0);                MagickResizeImage($wnd, $fWidth, $fHeight, MW_CubicFilter, $blur);         error_log("Resize Done", 0);                        /*        crop image        place image with alpha        repeat        */                MagickCropImage($wnd, $mergeWidth, $mergeHeight, $sx, $sy);        error_log("MagickCropImage", 0);        //MagickSetImageOpacity($wnd, ($alpha/100));        MagickEvaluateImage($wnd, MW_DivideEvaluateOperator, (100/$alpha), MW_AlphaChannel);        error_log("MagickSetImageOpacity", 0);        MagickCompositeImage($background, $wnd, MW_DissolveCompositeOp, $dx, $dy);        error_log("MagickCompositeImage", 0);        DestroyMagickWand($wnd);        error_log("DestroyMagickWand", 0);            }        if(!empty($infoLayer) && file_exists($infoLayer)){                error_log("Info Layer: ".$infoLayer, 0);                $infoWnd = NewMagickWand();        MagickReadImage($infoWnd, $infoLayer);                $infoImageWidth = MagickGetImageWidth($infoWnd);        $infoImageHeight = MagickGetImageHeight($infoWnd);                if ($infoImageWidth != $bgrWidth || $infoImageHeight != $bgrHeight) {            error_log("Start Info Layer Resize", 0);                    MagickResizeImage($infoWnd, $bgrWidth, $bgrHeight, MW_CubicFilter, 0.5);             error_log("End Info Layer Resize", 0);                }                error_log("Start Info Layer Composite", 0);                MagickCompositeImage($background, $infoWnd, MW_DissolveCompositeOp, 0, 0);        error_log("End Info Layer Composite", 0);                DestroyMagickWand($infoWnd);        error_log("Destroy Info Layer", 0);                    }            try {        //add cut template calibration        $margin = 100;        $diameter = 75;                $draw = NewDrawingWand();                $drawBackgroundColor = NewPixelWand();        PixelSetColor($drawBackgroundColor, "white");                DrawSetFillColor($draw, $drawBackgroundColor);        DrawSetStrokeColor($draw, $drawBackgroundColor);        DrawSetStrokeWidth($draw, 1);        DrawSetStrokeAntialias($draw, FALSE);        error_log("Set Rect Attribs", 0);        DrawRectangle($draw, 0, 0, $bgrWidth, $margin);        DrawRectangle($draw, 0, $bgrHeight, $bgrWidth, ($bgrHeight - $margin));        DrawRectangle($draw, 0, 0, $margin, $bgrHeight);        DrawRectangle($draw, $bgrWidth-$margin,0, $bgrWidth, $bgrHeight);        error_log("Draw Rectangles", 0);        MagickDrawImage($background, $draw);        error_log("Draw Image", 0);                        $drawCircleColor = NewPixelWand();        PixelSetColor($drawCircleColor, "black");        error_log("Create Pixel Colors", 0);        DrawSetFillColor($draw, $drawCircleColor);        DrawSetStrokeColor($draw, $drawCircleColor);        DrawSetStrokeWidth($draw, 0);        DrawSetStrokeAntialias($draw, TRUE);        error_log("Set Circle Attribs", 0);        DrawEllipse($draw, 37, 37, 37, 37, 0, 360);        DrawEllipse($draw, ($bgrWidth - 38), 37, 37, 37, 0, 360);        DrawEllipse($draw, ($bgrWidth - 38), ($bgrHeight/2), 37, 37, 0, 360);        DrawEllipse($draw, ($bgrWidth - 38), ($bgrHeight - 38), 37, 37, 0, 360);        DrawEllipse($draw, 37, ($bgrHeight - 38), 37, 37, 0, 360);        error_log("Draw Circles", 0);        MagickDrawImage($background, $draw);        error_log("Draw Image", 0);        error_log("End Adding Print Calibration", 0);    } catch(Exception $z){        $error = "Could not create image calibration template";     }     error_log("Saving: ".$finalFileName, 0);    //imagepng($background, $relativeGraphicsPath.$finalFileName);    MagickSetImageCompression($background, MW_JPEGCompression);    MagickSetImageCompressionQuality($background, 100);    MagickWriteImage($background, $relativeGraphicsPath.$finalFileName);    DestroyMagickWand($background);    error_log("Saved: ".$finalFileName, 0);    unset($background);}    ?>