Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

gdlib rahmen um img

Empfohlene Antworten

Veröffentlicht

hi und hallo,

ich hoffe mich vesteht jemand.

zuerst mal der link auf das was ich gerne hätte:

testpic

nun isses so, dass ich ein kleines cms oder einfach ne verwaltung programmiere.

der kunde möchte gerne diese "abgerundete sache" haben.

also: er lädt ein bild hoch (vorgegebene grösse) und daraus soll dann ein bild werden über dem sozusagen noch dieser graue abgerundete rahmen mit der weissen abgerundeten fläche links oben liegen soll.

nun frage ich mich ob das evtl mit der gd lib möglich ist.

ich denke daran die farben und pixelpositionen zu definieren, diese über das bild zu legen und somit ein "neues" bild zu schaffen das dann abgespeichert wird.

hab ich da aussicht auf erfolg? hat jemand sowas schon gemacht?

vielen dank

Das sollte eigentlich funtktionieren. Du kannst Bilder* aus Dateien erstellen. Du kannst Bilder komplett oder Ausschnitte davon in ein anderes kopieren und du kannst einfache Formen (Line, Kreis, etc.) erzeugen.

* Bild = GD-Bild-Instanz

Servus forTeeSake!

also ich würde erstmal diese Basisklassen verwenden. (die übrigens von mir sind :-))


// Image-Basis-Objekt
class Image {
var $sFile;
var $oImage = null;

function Image($sFile) {
$this->sFile = strtolower($sFile);
$this->oImage = $this->getImageResource();
}

function getImageResource() {
trigger_error("Unsupported imageformat! File: '". $this->getFile() ."'", E_USER_ERROR);
}

function getImageHeight() {
return imagesy($this->getImageResource());
}

function getImageWidth() {
return imagesx($this->getImageResource());
}

function getFile() {
return $this->sFile;
}

function getFileName() {
return substr(strrchr($this->getFile(), "/"), 1);
}

function getFilePath() {
return substr($this->getFile(), 0, strrpos($this->getFile(), "/") + 1 );
}

function getImage() {
trigger_error("Unsupported imageformat! File: '". $this->getFile() ."'", E_USER_ERROR);
}

function getThumbnail(&$sDestination, $iWidth = null, $iHeight = null) {
if ($sDestination { strlen($sDestination) - 1 } != "/") $sDestination .= "/";
$sDestination .= str_replace(array("..", "."), array("__", "_"), $this->getFilePath());

$sFileLocation = $sDestination . $this->getFileName();

// Wenn schon ein thumbnail vorhanden ist, den Pfad zu diesem zurückgeben
if ( file_exists( $sFileLocation)) {
$sDestination = $sFileLocation;
return null;
}

$oSrcImg = $this->getImageResource();
$iImgWidth = $this->getImageWidth();
$iImgHeight = $this->getImageHeight();

// Ordnerstruktur anlegen
$this->makedir($sDestination);

$sDestination = $sFileLocation;

if ($iImgHeight > $iImgWidth) {
// Hochkanntbilder proportional verkleinern
$iHeight = $iWidth;
$iWidth = null;
}

if (is_null($iWidth) && is_null($iHeight) || ($iImgWidth <= $iWidth && $iImgHeight <= $iHeight)) {
// Weder Höhe noch Breite wurden angegeben oder
// Die Höhe und Breite des Original Images ist schon kleiner als das Thumbnail das erstellt würde
// => pfad auf das Original Image zurückgeben
$sDestination = $this->getFile();
return null;
} else if (is_null($iWidth)) {
// Breite wurde angegebene, dazu die Höhe errechen
$iWidth = ($iImgWidth / $iImgHeight) * $iHeight;
} else if (is_null($iHeight)) {
// Höhe wurde angegeben, dazu die Breite errechnen
$iHeight = ($iImgHeight / $iImgWidth) * $iWidth;
}

$oThumbnail = imagecreatetruecolor($iWidth, $iHeight);
imagecopyresized($oThumbnail, $oSrcImg, 0, 0, 0, 0, $iWidth, $iHeight, $iImgWidth, $iImgHeight);

return $oThumbnail;
}

function makedir($sDir) {
$aDir = explode("/", $sDir);
$sParentDir = "";

foreach ($aDir as $sDirPart) {
if ( $sDirPart == "") continue;

$sCurrentDir = $sParentDir . $sDirPart . "/";

if (!is_dir($sCurrentDir)) {
mkdir($sCurrentDir);
}

$sParentDir = $sCurrentDir;
}
}
}
/* GIF Bilder sind mit der GD-Lib nicht mehr möglich!

// GIF-Format Objekt
class ImageGif extends Image {
function getImageResource() {
if (is_null($this->oImage)) {
$this->oImage = imagecreatefromgif($this->getFile());
}

return $this->oImage;
}

function getImage() {
return imagegif($this->getImageResource(), $this->getFile());
}

function getThumbnail($sDestinationDir, $iWidth = null, $iHeight = null) {
$oThumbnail = parent :: getThumbnail($sDestinationDir, $iWidth, $iHeight);
return imagegif($oThumbnail, $sDestinationDir.$this->getFileName());
}
}
*/

// JPG-Format Objekt
class ImageJpg extends Image {
function getImageResource() {
if (is_null($this->oImage)) {
$this->oImage = imagecreatefromjpeg($this->getFile());
}

return $this->oImage;
}

function getImage() {
return imagejpeg($this->getImageResource(), $this->getFile());
}

function getThumbnail($sDestination, $iWidth = null, $iHeight = null) {
$oThumbnail = parent :: getThumbnail($sDestination, $iWidth, $iHeight);

if ( !is_null($oThumbnail)) {
imagejpeg($oThumbnail, $sDestination);
}

return $sDestination;
}
}


// PNG-Format Objekt
class ImagePng extends Image {
function getImageResource() {
if (is_null($this->oImage)) {
$this->oImage = imagecreatefrompng($this->getFile());
}

return $this->oImage;
}

function getImage() {
return imagepng($this->getImageResource(), $this->getFile());
}

function getThumbnail($sDestination, $iWidth = null, $iHeight = null) {
$oThumbnail = parent :: getThumbnail($sDestination, $iWidth, $iHeight);

if ( !is_null($oThumbnail)) {
imagepng($oThumbnail, $sDestination);
}

return $sDestination;
}
}

// Factory zum erstellen von Image-Objekten
class ImageFactory {
function getImage( $sFileName) {
if (!file_exists($sFileName)) {
trigger_error("File '".$sFileName."' does not exist!", E_USER_ERROR);
}

$sFileType = strtolower(substr(strrchr($sFileName, "."), 1));

switch ($sFileType) {
case "jpeg" :
case "jpg" : return new ImageJpg($sFileName);
// case "gif" : return new ImageGif($sFileName);
case "png" : return new ImagePng($sFileName);

default : return new Image($sFileName);
}
}
}
?>
[/PHP]

Diese würd ich jetzt erweitern mit den Funktionen :

http://de3.php.net/manual/en/function.imageline.php (Zum linien Zeichen)

http://de3.php.net/manual/en/function.imageellipse.php (Zum Kreis Zeichnen)

und fertig :-)

hammer hammer. und cool dass das geht. der kunde wird sich freuen ;)

vielen dank!

übrigens:

Wenn du die neuste GD-Lib verwendest, ist GIF Support auch wieder möglich....

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.