Re: Infoga bilder
Postat: 22 aug 2016 17:43
Tapatalk torde inte vara relevant för denna övning då de bilderna processas och hostas av tapatalk.
Kod: Markera allt
// Modify these params accordingly to suit your installation
$nMaxWidth = 1024;
$nMaxHeight = 1024;
$nJPEGCompression = 75;
$imgMaxBytes = 256*1024;
// You may want to modify this "if this attachment an image" check.. at the moment I'm using this:
if (strpos($file->get('mimetype'), 'image/') === 0) {
$sImgSourceFilename = $file->get('filename');
$imgBytes = $file->get('filesize');
if ($arrImageData = @getimagesize($sImgSourceFilename)) {
$nImageType = $arrImageData[2];
switch ($nImageType) {
case IMG_GIF:
$imgSource = @imagecreatefromgif($sImgSourceFilename);
break;
case IMG_JPG:
$imgSource = @imagecreatefromjpeg($sImgSourceFilename);
break;
case IMG_PNG:
$imgSource = @imagecreatefrompng($sImgSourceFilename);
break;
case IMG_WBMP:
$imgSource = @imagecreatefromwbmp($sImgSourceFilename);
break;
default:
$imgSource = null;
break;
}
// Assuming we managed to read in the image OK..
if ($imgSource) {
$nImgWidth = $arrImageData[0];
$nImgHeight = $arrImageData[1];
$doResize = false;
/* $exif = exif_read_data($sImgSourceFilename);
if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 3:
$imgSource2 = imagerotate($imgSource, 180, 0);
$doResize = true;
break;
case 6:
$imgSource2 = imagerotate($imgSource, -90, 0);
$nImgWidth = $arrImageData[1];
$nImgHeight = $arrImageData[0];
$arrImageData[1] = $nImgWidth;
$arrImageData[0] = $nImgHeight;
$doResize = true;
break;
case 8:
$imgSource2 = imagerotate($imgSource, 90, 0);
$nImgWidth = $arrImageData[1];
$nImgHeight = $arrImageData[0];
$arrImageData[1] = $nImgWidth;
$arrImageData[0] = $nImgHeight;
$doResize = true;
break;
}
imageDestroy($imgSource);
$imgSource = $imgSource2;
}
*/
if ($nImgHeight > $nMaxHeight || $nImgWidth > $nMaxWidth || $imgBytes > $imgMaxBytes) {
$doResize = true;
// otherwise image width and/or height exceed our max dimensions
// work out the new widht/height for downward proportional resampling:
if ($nImgHeight > $nMaxHeight) {
$nRatio = ($nImgWidth / $nImgHeight);
$nImgHeight = $nMaxHeight;
$nImgWidth = round($nMaxHeight * $nRatio);
}
if ($nImgWidth > $nMaxWidth) {
$nRatio = ($nImgHeight / $nImgWidth);
$nImgWidth = $nMaxWidth;
$nImgHeight = round($nMaxWidth * $nRatio);
}
}
if ($doResize) {
$imgScaled = ImageCreateTrueColor($nImgWidth, $nImgHeight);
if (imagecopyresampled($imgScaled, $imgSource, 0, 0, 0, 0, $nImgWidth, $nImgHeight, $arrImageData[0], $arrImageData[1]))
imagejpeg($imgScaled, $sImgSourceFilename, $nJPEGCompression);
imageDestroy($imgScaled);
}
imageDestroy($imgSource);
}
}
}
Skickat.TiborBlomhall skrev:OK, hinner inte mer idag.
Återställt koden till det gamla.
Kan nån mejla mig 4 iPhone bilder tagna ett åt varje håll (dvs med 90 graders rotation mellan varje bild?) så kan jag testa själv?
tibor.blomhall teslaclubsweden.se
Jag är ingen expert på php, men du kopierar bredd till bredd och höjd till höjd. Ska det inte index 0 och 1 vara tvärtom i de sista raderna?TiborBlomhall skrev:Förresten det är ju massor med folk som kan mer om php än mig här på forumet. Vad är det som är fel:Kod: Markera allt
$imgSource2 = imagerotate.... $nImgWidth = $arrImageData[1]; $nImgHeight = $arrImageData[0]; $arrImageData[1] = $nImgWidth; $arrImageData[0] = $nImgHeight;
Tack men nån som kan ladda upp direkt från iphone via webbsidan, inte Tapatalk.Tars skrev:
Ska vara uppochner
Aha, sorry.TiborBlomhall skrev:Tack men nån som kan ladda upp direkt från iphone via webbsidan, inte Tapatalk.Tars skrev:
Ska vara uppochner