imagecreatetruecolor( $imgwidth, $imgheight ) kan max sættes til "400px, 400px"
Hej Eksperter.Jeg sidder og roder med en kode til at klippe en ellipseform ud af et billede.
Jeg oplever dog, at imagecreatetruecolor( $imgwidth, $imgheight ) højst vil give mig en hvid baggrund på 400px. Jeg synes dog ikke, jeg kan finde det som et kendt problem på Google. Er der nogen, der har erfaring med dette?
Prøv selv med denne kode:
<?php
// Created by NerdsOfTech
// Step 1 - Start with image as layer 1 (canvas)
$img1 = ImageCreateFromjpeg("test.jpg");
$imgwidth = imagesx($img1);
$imgheight = imagesy($img1);
$circlewidth = 400;
$circleheight = 400;
$x = $imgwidth / 2;
$y = $imgheight / 2;
// Step 2 - Create a blank image
$img2 = imagecreatetruecolor( $imgwidth, $imgheight );
$bg = imagecolorallocate($img2, 255, 255, 255); // white background
imagefill($img2, 0, 0, $bg);
// Step 3 - Create the ellipse OR circle mask
$e = imagecolorallocate($img2, 0, 0, 0); // black mask color
// Draw a ellipse mask
imagefilledellipse ($img2, $x, $y, $circlewidth, $circleheight, $e);
// Step 4 - Make shape color transparent
imagecolortransparent($img2, $e);
// Step 5 - Merge the mask into canvas with 100 percent opacity
imagecopymerge($img1, $img2, 0, 0, 0, 0, $circlewidth, $circleheight, 100);
// Step 6 - Make outside border color around circle transparent
imagecolortransparent($img1, $bg);
// Step 7 - Output merged image
header("Content-type: image/png"); // output header
imagepng($img1); // output merged image
// Or export to file with:
// imagepng( $img1,'testresult.png' );
// Step 8 - Cleanup memory
imagedestroy($img2); // kill mask first
imagedestroy($img1); // kill canvas last
På forhånd mange tak!
Med venlig hilsen
Tobias
