Förminska genomskinliga bilder utan att få svart bakgrund
ProgrammeringEtt problem som normalt uppstår när man automatiskt förminskar bilder vid uppladdning på en webbsida kan lätt avhjälpas med nedanstående kod. Kraven är att man använder sig av PHP och biblioteket GD. Detta är ingen fullständig kod utan illustrerar var man sätter in koden för transparens och det är mellan imagecreatetruecolor() och imagecopyresampled()
$image = imagecreatetruecolor($thumb_width, $thumb_height);
//Kollar om det är en PNG
if(preg_match("/image/.*?(png)/", $strFileType))
{
imagealphablending($image, false);
imagesavealpha($image, true);
$transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefilledrectangle($image, 0, 0, $thumb_width, $thumb_height, $transparent);
}
imagecopyresampled($image, $new, 0, 0, 0, 0, $thumb_width, $thumb_height, imagesx($new), imagesy($new));
//Kollar om det är en PNG
if(preg_match("/image/.*?(png)/", $strFileType))
{
imagealphablending($image, false);
imagesavealpha($image, true);
$transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefilledrectangle($image, 0, 0, $thumb_width, $thumb_height, $transparent);
}
imagecopyresampled($image, $new, 0, 0, 0, 0, $thumb_width, $thumb_height, imagesx($new), imagesy($new));
Sök
@frostkom
- RT @grigs: The average person looks at their phone 150 times a day http://t.co/TpX1HQSL« Svara (Igår 15:13)
- RT @mezzoblue: Time to stop feeling guilty about the occasional Starbucks trip and support them, if this is the BS they're up against: h ...« Svara (I måndags 21:25)
- RT @lukew: Time to start testing Web sites on Kindles? http://t.co/E3nD5JOH« Svara (I måndags 21:19)
- Krilleee!!! Cracks me up everytime« Svara (I söndags 21:45)
- RT @shoffis: iPhone 5 är här! ;) http://t.co/wI9mDOes« Svara (I fredags 21:47)


