Jak tworzyć miniatury o jednakowej wysokości.

cavvy

Avatar: cavvy

2011-11-26 09:49

Chcę zmienić tworzenie miniatur tak, aby wszystkie miały jednakową wysokosć, a nie jak jest domyślnie szerokość.

Próbowałam pozamieniać nazwy w pliku FotoJobs na zasadzie ThumbX <-> ThumbY ScaleX<->ScaleY
Ale nic to nie dało.

Jak tylko zmieniłam w niektórych przypadkach w funkcji copyAndCreateThumb działało, ale skrypt ignorował ustawienia z general.php i tworzył miniatury domyślnie na 100px wysokie a ja potrzebuje do wyboru miec 200 lub 350px.

» Quick.Cms v3.x

pxl666

Avatar: pxl666

2011-11-26 14:23

mozesz to zrobic w CSS nadajac parametr maxheight (mam nadzieje ze dobrze powiedzialem z pamieci...)

cavvy

Avatar: cavvy

2011-11-26 14:57

To jest takie robienie na sztywno. W tej chwili mam na sztywno w pliku odpowiadającym za generowanie contentu, wysokość dla plików wyświetlanych z listy.

Znalazłam na forum generowanie kwadratów,ale też mi to wiele nie pomaga.

na chwilę obecną mam 2 pliki pages.tpl wiec jakos moge to rozdzielic. jednak jakby ktos dal radę rozwiazać ten problem byłoby idealnie.

Makaron

Avatar: Makaron

2011-11-28 15:03

Był taki temat już kiedyś, jest dodany nawet do FAQ: http://opensolution.org/Quick.Cart/forum/?p=readTopic&nr=6444

I helped? Like it: www.facebook.com/makwebpl

cavvy

Avatar: cavvy

2011-12-08 10:46

tylko że tam jest opisana solucja dla kwadratów, a ja chce dalej prostokaty, ale żeby ustawiona wartosć z panelu 200 czy 150 odnosiła sie nie do szerokosci tylko wysokosci.

boboo

Avatar: boboo

2011-12-09 13:29

Trochę przejaskrawione (długie zdjęcie), ale czy chodzi o to?
http://www.kimla.de/bilder/same_height.png
Taka sama wysokość niezależnie od szerokości.

qc-plugins.kimla.de

Rad

Avatar: Rad

2011-12-21 16:46

O to chodzi... Jak to zrobić?

DonnaD

Avatar: DonnaD

2012-05-17 18:03

Plik php wygląda tak...

<?php
/**
* FotoJobs - changing photos
* @access public
* @version 0.3
* @require FileJobs
* @require Trash
*/
final class FotoJobs extends FileJobs
{

private $iThumbX = 100;
private $iThumbY = 100;
private $iQuality = 80;
private $iGifQuality = 100;
private $iThumbAdd = '_m';
private $iCustomThumbX = 250;
private $iCustomThumbY = 250;
private $sCustomThumbAdd = null;
private $sExt = 'jpg';
private $sExtDot = '.jpg';
private $fRatio = 0.80;
private static $oInstance = null;
public $iMaxForThumbSize = 2000;
private $aBackgroundGif = Array( 'red' => 255, 'green' => 255, 'blue' => 255 );

public static function getInstance( ){
if( !isset( self::$oInstance ) ){
self::$oInstance = new FotoJobs( );
}
return self::$oInstance;
} // end function getInstance

/**
* Constuctor
* @return void
* @param int $iThumbSize
*/
private function __construct( $iThumbSize = 100 ){
$this->iThumbX = $iThumbSize;
} // end function __construct

/**
* Sets thumb size
* @return void
* @param int $iThumbSize
*/
public function setThumbSize( $iThumbSize = 100 ){
$this->iThumbX = $iThumbSize;
} // end function setThumbSize

/**
* Sets thumb quality
* @return void
* @param int $iThumbQuality
*/
public function setThumbQuality( $iThumbQuality = 80 ){
$this->iQuality = $iThumbQuality;
} // end function setThumbQuality

/**
* Sets name addition for thumb
* @return void
* @param int $iThumbAdd
*/
public function setThumbAdd( $iThumbAdd = '_m' ){
$this->iThumbAdd = $iThumbAdd;
} // end function setThumbAdd

/**
* Sets name addition for custom thumb
* @return void
* @param int $iThumbAdd
*/
public function setCustomThumbAdd( $sThumbAdd = null ){
$this->sCustomThumbAdd = $sThumbAdd;
} // end function setCustomThumbAdd

/**
* Sets max dimension of picture (when bigger thumb wont be create)
* @return void
* @param int $iMaxForThumbSize
*/
public function setMaxForThumbSize( $iMaxForThumbSize = 2000 ){
$this->iMaxForThumbSize = $iMaxForThumbSize;
} // end function setMaxForThumbSize

/**
* Sets ratio of image
* @return void
* @param int $fRatio
*/
public function setRatio( $fRatio = 0.80 ){
$this->fRatio = $fRatio;
} // end function setRatio

/**
* Upload and copy of files and create thumbs from them
* @return array
* @param string $sDestDir - destination directory
* @param mixed $mImgSrc - when upload = $_FILES or when copy = file path
* @param string $sImgOutput - suggested output file name
* @param mixed $sOption - upload or copy
*/
public function copyAndCreateThumb( $sDestDir, $mImgSrc, $sImgOutput, $sOption = null ){

// remember thumb size
$iOldSize = $this->iThumbX;

if( !is_dir( $sDestDir ) )
return null;

$sImgOutput = $this->throwNameOfFile( $sImgOutput );

$sImgOutput = $this->changeFileName( $sImgOutput );

if( $sOption == 'upload' ){
if( is_uploaded_file( $mImgSrc['tmp_name'] ) && is_file( $mImgSrc['tmp_name'] ) && filesize( $mImgSrc['tmp_name'] ) > 0 && $this->checkCorrectFile( $mImgSrc['name'], 'jpg|jpeg|gif|png' ) == 1 ){
$this->sExt = $this->throwExtOfFile( $mImgSrc['name'] );
$this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
$aNewFiles['bFile'] = $this->uploadFile( $mImgSrc, $sDestDir, $sImgOutput.$this->sExtDot );
}
else
return null;
}
elseif( $sOption == 'copy' ){
if( is_file( $mImgSrc ) && filesize( $mImgSrc ) > 0 && $this->checkCorrectFile( $mImgSrc, 'jpg|jpeg|gif|png' ) == 1 ){
$this->sExt = $this->throwExtOfFile( $mImgSrc );
$this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
$aNewFiles['bFile'] = $this->checkIsFile( $sImgOutput.$this->sExtDot, $sDestDir );
if( !copy( $mImgSrc, $sDestDir.$aNewFiles['bFile'] ) )
return null;
}
else
return null;
}
$sImgPatch = $sDestDir.$aNewFiles['bFile'];

$aNewFiles['bName'] = $this->throwNameOfFile( $aNewFiles['bFile'] );
$aNewFiles['sFile'] = $aNewFiles['bName'] . $this->iThumbAdd . '.' . $this->sExtDot;
$aImgSize = $this->throwImgSize( $sImgPatch );

if( defined( 'MAX_DIMENSION_OF_IMAGE' ) && ( $aImgSize['width'] > MAX_DIMENSION_OF_IMAGE || $aImgSize ['height'] > MAX_DIMENSION_OF_IMAGE ) ){
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){
$iOldAdd = $this->iThumbAdd;
$this->setThumbSize( MAX_DIMENSION_OF_IMAGE );
$this->setThumbAdd( '' );
$aNewFiles['bFile'] = $this->createThumb( $sImgPatch, $sDestDir, $aNewFiles['bFile'] );
$this->setThumbSize( $iOldSize );
$this->setThumbAdd( $iOldAdd );
}
else
return null;
}

if( $aImgSize['width'] >= $this->iThumbX || $aImgSize['height'] >= $this->iThumbX ){
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize )
$aNewFiles['sFile'] = $this->createThumb( $sImgPatch, $sDestDir );
else
return null;
}
else
copy( $sImgPatch, $sDestDir.$aNewFiles['sFile'] );

$aNewFiles['bWidth'] = $aImgSize['width'];
$aNewFiles['bHeight'] = $aImgSize['height'];
$aNewFiles['sWidth'] = $this->iThumbX;
$aNewFiles['sHeight'] = $this->iThumbY;
$aNewFiles['sName'] = basename( $aNewFiles['sFile'], '.'.$this->sExt );
$aNewFiles['ext'] = $this->sExt;

$this->iThumbY = 100;
$this->setThumbSize( $iOldSize );

return $aNewFiles;
} // end function copyAndCreateThumb

/**
* Clears propeties of object (set to default)
* @return void
*/
public function clearAll( ){
$this->iThumbX = 100;
$this->iThumbY = 100;
} // end function clearAll

/**
* Returns image size in px
* @return array/int
* @param string $imgSrc
* @param mixed $sOption
*/
public function throwImgSize( $imgSrc, $sOption = null ){
$aImg = getImageSize( $imgSrc );

$aImgSize['width'] = $aImg[0];
$aImgSize['height'] = $aImg[1];

if( $sOption == 'width' || $sOption == 'height' )
return $aImgSize[$sOption];
else
return $aImgSize;
} // end function throwImgSize

/**
* Returns image width in px
* @return int
* @param string $imgSrc
*/
public function throwImgWidth( $imgSrc ){
return $this->throwImgSize( $imgSrc, 'width' );
} // end function throwImgWidth

/**
* Returns image height in px
* @return int
* @param string $imgSrc
*/
public function throwImgHeight( $imgSrc ){
return $this->throwImgSize( $imgSrc, 'height' );
} // end function throwImgHeight


/**
* Creates new custom size thumb
* @return string
* @param string $sImgSource
* @param string $sImgDestDir
* @param int $iSize
* @param string $sImgOutput
* @param bool $bOverwrite
*/
public function createCustomThumb( $sImgSource, $sImgDestDir, $iSize = null, $sImgOutput = false, $bOverwrite = null ){

if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
return null;

$aImgSize = $this->throwImgSize( $sImgSource );
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){

$sImgExt = $this->throwExtOfFile( $sImgSource );

if( $sImgOutput == false )
$sImgOutput = $this->throwNameOfFile( $sImgSource ) . $this->sCustomThumbAdd . '.' . $sImgExt;

if( !isset( $bOverwrite ) )
$sImgOutput = $this->checkIsFile( $sImgOutput, $sImgDestDir );

$iOldSize = $this->iThumbX;
if( is_numeric( $iSize ) )
$this->setThumbSize( $iSize );
else
$this->setThumbSize( $this->iCustomThumbX );

$sFile = $this->createThumb( $sImgSource, $sImgDestDir, $sImgOutput );
$this->setThumbSize( $iOldSize );
return $sFile;
}
else
return null;
} // end function createCustomThumb


/**
* Function make photo thumbs
* @return int
* @param string $sImgSource - source file, from it thumb is created
* @param string $sImgDestDir - destination directory for thumb
* @param string $sImgOutput - picture name after change (default old name with _m addition)
* @param mixed $sOption - b/d
*/
public function createThumb( $sImgSource, $sImgDestDir, $sImgOutput = false, $iQuality = null, $sOption = null ) {

if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
return null;

if( !is_numeric( $iQuality ) )
$iQuality = $this->iQuality;

$sImgExt = $this->throwExtOfFile( $sImgSource );

if( $sImgOutput == false )
$sImgOutput = basename( $sImgSource, '.'.$sImgExt ) . $this->iThumbAdd . '.' . $sImgExt;

$sImgOutput = $this->changeFileName( $sImgOutput );

$sImgBackup = $sImgDestDir.$sImgOutput . "_backup.jpg";
copy( $sImgSource, $sImgBackup );
$aImgProperties = GetImageSize( $sImgBackup );

if ( !$aImgProperties[2] == 2 ) {
return null;
}
else {
switch( $sImgExt ) {
case 'jpg':
$mImgCreate = ImageCreateFromJPEG( $sImgBackup );
break;
case 'jpeg':
$mImgCreate = ImageCreateFromJPEG( $sImgBackup );
break;
case 'png':
$mImgCreate = ImageCreateFromPNG( $sImgBackup );
break;
case 'gif':
$mImgCreate = ImageCreateFromGIF( $sImgBackup );
}

$iImgCreateX = ImageSX( $mImgCreate );
$iImgCreateY = ImageSY( $mImgCreate );

$iScaleX = $this->iThumbX / ( $iImgCreateX );
$this->iThumbY = $iImgCreateY * $iScaleX;

$iRatio = $this->iThumbX / $this->iThumbY;

if( $iRatio < $this->fRatio ) {
$this->iThumbY = $this->iThumbX;
$iScaleY = $this->iThumbY / ( $iImgCreateY );
$this->iThumbX = $iImgCreateX * $iScaleY;
}

$this->iThumbX = ( int )( $this->iThumbX );
$this->iThumbY = ( int )( $this->iThumbY );


$mImgDest = imagecreatetruecolor( $this->iThumbX, $this->iThumbY );

if( $sImgExt == 'png' ){
imagealphablending( $mImgDest, false );
$iTransparent = imagecolorallocatealpha( $mImgDest, 0, 0, 0, 127 );
imagecolortransparent( $mImgDest, $iTransparent );
imagefill( $mImgDest, 0, 0, $iTransparent );
imagesavealpha( $mImgDest, true );
}
elseif ($sImgExt == 'gif'){
imagealphablending( $mImgDest, true );
imagesavealpha( $mImgDest, false );
$iBackgroundGif = imagecolorallocate( $mImgDest, $this->aBackgroundGif['red'], $this->aBackgroundGif['green'],$this->aBackgroundGif['blue'] );
imagefill( $mImgDest, 0, 0, $iBackgroundGif );
}

unlink( $sImgBackup );

if( function_exists( 'imagecopyresampled' ) )
$sCreateFunction = 'imagecopyresampled';
else
$sCreateFunction = 'imagecopyresized';

if( !$sCreateFunction( $mImgDest, $mImgCreate, 0, 0, 0, 0, $this->iThumbX + 1, $this->iThumbY + 1, $iImgCreateX, $iImgCreateY ) ) {
imagedestroy( $mImgCreate );
imagedestroy( $mImgDest );
return null;
}
else {
imagedestroy( $mImgCreate );
if( !is_file( $sImgDestDir.$sImgOutput ) ) {
touch( $sImgDestDir.$sImgOutput );
chmod( $sImgDestDir.$sImgOutput, 0666 );
}
switch( $sImgExt ) {
case 'jpg':
$Image = ImageJPEG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
break;
case 'jpeg':
$Image = ImageJPEG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
break;
case 'png':
$Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput );
break;
case 'gif':
if( function_exists( "imagegif" ) )
$Image = ImageGIF( $mImgDest, $sImgDestDir.$sImgOutput );
else{
if( $iQuality > 0 )
$iQuality = floor( ( $iQuality - 1 ) / 10 );
$Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
}
}
if ( $Image ) {
imagedestroy( $mImgDest );
return $sImgOutput;
}
imagedestroy( $mImgDest );
}
return null;
}

} // end function createThumb

};


?>

ale mimo to, kwadraty przyjmują formę tylko 150 x 100, przy wiekszych, zdjecie jest skalowane do tego rozmiaru. Mam ten sam problem co cavvy, chciałabym żeby wszystkie miniatury miały jednakową wysokosć, a nie jak jest domyślnie szerokość. Na dzień dzisiejszy mam kwadraty o wielkości 150 x 100. Przy mniejszych nie ma problemu, układają się "nierówno", ale układają. Większe niz 150 x 100 jednak nie będą... system generuje tylko kwadraty.

boboo

Avatar: boboo

2012-05-17 21:12

Najprościej tak:
w pliku image-jobs.php lub FotoJobs.php (w starszych wersjach),
w funkcji createThumb
zamienić:
$iScaleX=$this->iThumbX / ($iImgCreateX);
na:
$iScaleY=$this->iThumbY/($iImgCreateY);
następnie zamienić:
$this->iThumbY=$iImgCreateY * $iScaleX;
na:
$this->iThumbX=$iImgCreateX*$iScaleY;
i wykomentować lub wyrzucić to:
$iRatio=$this->iThumbX / $this->iThumbY;
if($iRatio < $this->fRatio) {
$this->iThumbY=$this->iThumbX;
$iScaleY=$this->iThumbY / ($iImgCreateY);
$this->iThumbX=$iImgCreateX * $iScaleY;
}
I to wszystko. Od tej chwili miniaturki nowo wgrywanych zdjęć będą miały jednakową wysokość a nie szerokość.

http://qc-plugins.kimla.de

DonnaD

Avatar: DonnaD

2012-05-22 20:54

Dziwna sprawa... zdjęcia zaczely mi się wyswietlac (po kliknięciu na miniaturkę) w rozmiarze ok. 100px jeden bok. Miniaturki wyświetlają się w jednakowym rozmiarze tylko przy ustawieniach 100.

DonnaD

Avatar: DonnaD

2012-05-22 23:05

boboo, albo kod jest przekręcony (to miniaturki + zdjecia w pelnym rozmiarze) zamieniły się miejscami... albo ja coś pokręciłam, co jest mało prawdopodobne. Czy mógłbyś sprawdzić poprawność tego kodu?

boboo

Avatar: boboo

2012-05-23 06:49

Jeszcze drobnostka:
w tyma samym pliku w funkcji setThumbSize należy zamienić X na Y
oraz:
$iOldSize = $this->iThumbX;
zamienić na
$iOldSize = $this->iThumbY;

qc-plugins.kimla.de

DonnaD

Avatar: DonnaD

2012-05-23 21:08

Teraz nie wyświetliła się wogole strona admina... (białe, puste tlo) oto kod:

<?php
/**
* FotoJobs - changing photos
* @access public
* @version 0.3
* @require FileJobs
* @require Trash
*/
final class FotoJobs extends FileJobs
{

private $iThumbX = 100;
private $iThumbY = 100;
private $iQuality = 80;
private $iGifQuality = 100;
private $iThumbAdd = '_m';
private $iCustomThumbX = 250;
private $iCustomThumbY = 250;
private $sCustomThumbAdd = null;
private $sExt = 'jpg';
private $sExtDot = '.jpg';
private $fRatio = 0.80;
private static $oInstance = null;
public $iMaxForThumbSize = 2000;
private $aBackgroundGif = Array( 'red' => 255, 'green' => 255, 'blue' => 255 );

public static function getInstance( ){
if( !isset( self::$oInstance ) ){
self::$oInstance = new FotoJobs( );
}
return self::$oInstance;
} // end function getInstance

/**
* Constuctor
* @return void
* @param int $iThumbSize
*/
private function __construct( $iThumbSize = 100 ){
$this->iThumbX = $iThumbSize;
} // end function __construct

/**
* Sets thumb size
* @return void
* @param int $iThumbSize
*/
public function setThumbSize( $iThumbSize = 100 ){
$this->iThumbX = $iThumbSize;
} // end function setThumbSize

/**
* Sets thumb quality
* @return void
* @param int $iThumbQuality
*/
public function setThumbQuality( $iThumbQuality = 80 ){
$this->iQuality = $iThumbQuality;
} // end function setThumbQuality

/**
* Sets name addition for thumb
* @return void
* @param int $iThumbAdd
*/
public function setThumbAdd( $iThumbAdd = '_m' ){
$this->iThumbAdd = $iThumbAdd;
} // end function setThumbAdd

/**
* Sets name addition for custom thumb
* @return void
* @param int $iThumbAdd
*/
public function setCustomThumbAdd( $sThumbAdd = null ){
$this->sCustomThumbAdd = $sThumbAdd;
} // end function setCustomThumbAdd

/**
* Sets max dimension of picture (when bigger thumb wont be create)
* @return void
* @param int $iMaxForThumbSize
*/
public function setMaxForThumbSize( $iMaxForThumbSize = 2000 ){
$this->iMaxForThumbSize = $iMaxForThumbSize;
} // end function setMaxForThumbSize

/**
* Sets ratio of image
* @return void
* @param int $fRatio
*/
public function setRatio( $fRatio = 0.80 ){
$this->fRatio = $fRatio;
} // end function setRatio

/**
* Upload and copy of files and create thumbs from them
* @return array
* @param string $sDestDir - destination directory
* @param mixed $mImgSrc - when upload = $_FILES or when copy = file path
* @param string $sImgOutput - suggested output file name
* @param mixed $sOption - upload or copy
*/
public function copyAndCreateThumb( $sDestDir, $mImgSrc, $sImgOutput, $sOption = null ){

// remember thumb size
$iOldSize = $this->iThumbX;

if( !is_dir( $sDestDir ) )
return null;

$sImgOutput = $this->throwNameOfFile( $sImgOutput );

$sImgOutput = $this->changeFileName( $sImgOutput );

if( $sOption == 'upload' ){
if( is_uploaded_file( $mImgSrc['tmp_name'] ) && is_file( $mImgSrc['tmp_name'] ) && filesize( $mImgSrc['tmp_name'] ) > 0 && $this->checkCorrectFile( $mImgSrc['name'], 'jpg|jpeg|gif|png' ) == 1 ){
$this->sExt = $this->throwExtOfFile( $mImgSrc['name'] );
$this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
$aNewFiles['bFile'] = $this->uploadFile( $mImgSrc, $sDestDir, $sImgOutput.$this->sExtDot );
}
else
return null;
}
elseif( $sOption == 'copy' ){
if( is_file( $mImgSrc ) && filesize( $mImgSrc ) > 0 && $this->checkCorrectFile( $mImgSrc, 'jpg|jpeg|gif|png' ) == 1 ){
$this->sExt = $this->throwExtOfFile( $mImgSrc );
$this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
$aNewFiles['bFile'] = $this->checkIsFile( $sImgOutput.$this->sExtDot, $sDestDir );
if( !copy( $mImgSrc, $sDestDir.$aNewFiles['bFile'] ) )
return null;
}
else
return null;
}
$sImgPatch = $sDestDir.$aNewFiles['bFile'];

$aNewFiles['bName'] = $this->throwNameOfFile( $aNewFiles['bFile'] );
$aNewFiles['sFile'] = $aNewFiles['bName'] . $this->iThumbAdd . '.' . $this->sExtDot;
$aImgSize = $this->throwImgSize( $sImgPatch );

if( defined( 'MAX_DIMENSION_OF_IMAGE' ) && ( $aImgSize['width'] > MAX_DIMENSION_OF_IMAGE || $aImgSize ['height'] > MAX_DIMENSION_OF_IMAGE ) ){
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){
$iOldAdd = $this->iThumbAdd;
$this->setThumbSize( MAX_DIMENSION_OF_IMAGE );
$this->setThumbAdd( '' );
$aNewFiles['bFile'] = $this->createThumb( $sImgPatch, $sDestDir, $aNewFiles['bFile'] );
$this->setThumbSize( $iOldSize );
$this->setThumbAdd( $iOldAdd );
}
else
return null;
}

if( $aImgSize['width'] >= $this->iThumbX || $aImgSize['height'] >= $this->iThumbX ){
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize )
$aNewFiles['sFile'] = $this->createThumb( $sImgPatch, $sDestDir );
else
return null;
}
else
copy( $sImgPatch, $sDestDir.$aNewFiles['sFile'] );

$aNewFiles['bWidth'] = $aImgSize['width'];
$aNewFiles['bHeight'] = $aImgSize['height'];
$aNewFiles['sWidth'] = $this->iThumbX;
$aNewFiles['sHeight'] = $this->iThumbY;
$aNewFiles['sName'] = basename( $aNewFiles['sFile'], '.'.$this->sExt );
$aNewFiles['ext'] = $this->sExt;

$this->iThumbY = 100;
$this->setThumbSize( $iOldSize );

return $aNewFiles;
} // end function copyAndCreateThumb

/**
* Clears propeties of object (set to default)
* @return void
*/
public function clearAll( ){
$this->iThumbX = 100;
$this->iThumbY = 100;
} // end function clearAll

/**
* Returns image size in px
* @return array/int
* @param string $imgSrc
* @param mixed $sOption
*/
public function throwImgSize( $imgSrc, $sOption = null ){
$aImg = getImageSize( $imgSrc );

$aImgSize['width'] = $aImg[0];
$aImgSize['height'] = $aImg[1];

if( $sOption == 'width' || $sOption == 'height' )
return $aImgSize[$sOption];
else
return $aImgSize;
} // end function throwImgSize

/**
* Returns image width in px
* @return int
* @param string $imgSrc
*/
public function throwImgWidth( $imgSrc ){
return $this->throwImgSize( $imgSrc, 'width' );
} // end function throwImgWidth

/**
* Returns image height in px
* @return int
* @param string $imgSrc
*/
public function throwImgHeight( $imgSrc ){
return $this->throwImgSize( $imgSrc, 'height' );
} // end function throwImgHeight


/**
* Creates new custom size thumb
* @return string
* @param string $sImgSource
* @param string $sImgDestDir
* @param int $iSize
* @param string $sImgOutput
* @param bool $bOverwrite
*/
public function createCustomThumb( $sImgSource, $sImgDestDir, $iSize = null, $sImgOutput = false, $bOverwrite = null ){

if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
return null;

$aImgSize = $this->throwImgSize( $sImgSource );
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){

$sImgExt = $this->throwExtOfFile( $sImgSource );

if( $sImgOutput == false )
$sImgOutput = $this->throwNameOfFile( $sImgSource ) . $this->sCustomThumbAdd . '.' . $sImgExt;

if( !isset( $bOverwrite ) )
$sImgOutput = $this->checkIsFile( $sImgOutput, $sImgDestDir );

$iOldSize = $this->iThumbX;
if( is_numeric( $iSize ) )
$this->setThumbSize( $iSize );
else
$this->setThumbSize( $this->iCustomThumbX );

$sFile = $this->createThumb( $sImgSource, $sImgDestDir, $sImgOutput );
$this->setThumbSize( $iOldSize );
return $sFile;
}
else
return null;
} // end function createCustomThumb


/**
* Function make photo thumbs
* @return int
* @param string $sImgSource - source file, from it thumb is created
* @param string $sImgDestDir - destination directory for thumb
* @param string $sImgOutput - picture name after change (default old name with _m addition)
* @param mixed $sOption - b/d
*/
public function createThumb( $sImgSource, $sImgDestDir, $sImgOutput = false, $iQuality = null, $sOption = null ) {

if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
return null;

if( !is_numeric( $iQuality ) )
$iQuality = $this->iQuality;

$sImgExt = $this->throwExtOfFile( $sImgSource );

if( $sImgOutput == false )
$sImgOutput = basename( $sImgSource, '.'.$sImgExt ) . $this->iThumbAdd . '.' . $sImgExt;

$sImgOutput = $this->changeFileName( $sImgOutput );

$sImgBackup = $sImgDestDir.$sImgOutput . "_backup.jpg";
copy( $sImgSource, $sImgBackup );
$aImgProperties = GetImageSize( $sImgBackup );

if ( !$aImgProperties[2] == 2 ) {
return null;
}
else {
switch( $sImgExt ) {
case 'jpg':
$mImgCreate = ImageCreateFromJPEG( $sImgBackup );
break;
case 'jpeg':
$mImgCreate = ImageCreateFromJPEG( $sImgBackup );
break;
case 'png':
$mImgCreate = ImageCreateFromPNG( $sImgBackup );
break;
case 'gif':
$mImgCreate = ImageCreateFromGIF( $sImgBackup );
}

$iImgCreateX = ImageSX( $mImgCreate );
$iImgCreateY = ImageSY( $mImgCreate );

$iScaleX = $this->iThumbX / ( $iImgCreateX );
$this->iThumbY = $iImgCreateY * $iScaleX;

$iRatio = $this->iThumbX / $this->iThumbY;

if( $iRatio < $this->fRatio ) {
$this->iThumbY = $this->iThumbX;
$iScaleY = $this->iThumbY / ( $iImgCreateY );
$this->iThumbX = $iImgCreateX * $iScaleY;
}

$this->iThumbX = ( int )( $this->iThumbX );
$this->iThumbY = ( int )( $this->iThumbY );


$mImgDest = imagecreatetruecolor( $this->iThumbX, $this->iThumbY );

if( $sImgExt == 'png' ){
imagealphablending( $mImgDest, false );
$iTransparent = imagecolorallocatealpha( $mImgDest, 0, 0, 0, 127 );
imagecolortransparent( $mImgDest, $iTransparent );
imagefill( $mImgDest, 0, 0, $iTransparent );
imagesavealpha( $mImgDest, true );
}
elseif ($sImgExt == 'gif'){
imagealphablending( $mImgDest, true );
imagesavealpha( $mImgDest, false );
$iBackgroundGif = imagecolorallocate( $mImgDest, $this->aBackgroundGif['red'], $this->aBackgroundGif['green'],$this->aBackgroundGif['blue'] );
imagefill( $mImgDest, 0, 0, $iBackgroundGif );
}

unlink( $sImgBackup );

if( function_exists( 'imagecopyresampled' ) )
$sCreateFunction = 'imagecopyresampled';
else
$sCreateFunction = 'imagecopyresized';

if( !$sCreateFunction( $mImgDest, $mImgCreate, 0, 0, 0, 0, $this->iThumbX + 1, $this->iThumbY + 1, $iImgCreateX, $iImgCreateY ) ) {
imagedestroy( $mImgCreate );
imagedestroy( $mImgDest );
return null;
}
else {
imagedestroy( $mImgCreate );
if( !is_file( $sImgDestDir.$sImgOutput ) ) {
touch( $sImgDestDir.$sImgOutput );
chmod( $sImgDestDir.$sImgOutput, 0666 );
}
switch( $sImgExt ) {
case 'jpg':
$Image = ImageJPEG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
break;
case 'jpeg':
$Image = ImageJPEG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
break;
case 'png':
$Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput );
break;
case 'gif':
if( function_exists( "imagegif" ) )
$Image = ImageGIF( $mImgDest, $sImgDestDir.$sImgOutput );
else{
if( $iQuality > 0 )
$iQuality = floor( ( $iQuality - 1 ) / 10 );
$Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
}
}
if ( $Image ) {
imagedestroy( $mImgDest );
return $sImgOutput;
}
imagedestroy( $mImgDest );
}
return null;
}

} // end function createThumb

};


?>

DonnaD

Avatar: DonnaD

2012-05-23 21:09

Wkleilam ten stary fotojobs.... po tym nie wchodziło:

<?php
/**
* FotoJobs - changing photos
* @access public
* @version 0.3
* @require FileJobs
* @require Trash
*/
final class FotoJobs extends FileJobs
{

private $iThumbX = 100;
private $iThumbY = 100;
private $iQuality = 80;
private $iGifQuality = 100;
private $iThumbAdd = '_m';
private $iCustomThumbX = 250;
private $iCustomThumbY = 250;
private $sCustomThumbAdd = null;
private $sExt = 'jpg';
private $sExtDot = '.jpg';
private $fRatio = 0.80;
private static $oInstance = null;
public $iMaxForThumbSize = 2000;
private $aBackgroundGif = Array( 'red' => 255, 'green' => 255, 'blue' => 255 );

public static function getInstance( ){
if( !isset( self::$oInstance ) ){
self::$oInstance = new FotoJobs( );
}
return self::$oInstance;
} // end function getInstance

/**
* Constuctor
* @return void
* @param int $iThumbSize
*/
private function __construct( $iThumbSize = 100 ){
$this->iThumbX = $iThumbSize;
} // end function __construct

/**
* Sets thumb size
* @return void
* @param int $iThumbSize
*/
public function setThumbSize( $iThumbSize = 100 ){
$this->iThumbX = $iThumbSize;
} // end function setThumbSize

/**
* Sets thumb quality
* @return void
* @param int $iThumbQuality
*/
public function setThumbQuality( $iThumbQuality = 80 ){
$this->iQuality = $iThumbQuality;
} // end function setThumbQuality

/**
* Sets name addition for thumb
* @return void
* @param int $iThumbAdd
*/
public function setThumbAdd( $iThumbAdd = '_m' ){
$this->iThumbAdd = $iThumbAdd;
} // end function setThumbAdd

/**
* Sets name addition for custom thumb
* @return void
* @param int $iThumbAdd
*/
public function setCustomThumbAdd( $sThumbAdd = null ){
$this->sCustomThumbAdd = $sThumbAdd;
} // end function setCustomThumbAdd

/**
* Sets max dimension of picture (when bigger thumb wont be create)
* @return void
* @param int $iMaxForThumbSize
*/
public function setMaxForThumbSize( $iMaxForThumbSize = 2000 ){
$this->iMaxForThumbSize = $iMaxForThumbSize;
} // end function setMaxForThumbSize

/**
* Sets ratio of image
* @return void
* @param int $fRatio
*/
public function setRatio( $fRatio = 0.80 ){
$this->fRatio = $fRatio;
} // end function setRatio

/**
* Upload and copy of files and create thumbs from them
* @return array
* @param string $sDestDir - destination directory
* @param mixed $mImgSrc - when upload = $_FILES or when copy = file path
* @param string $sImgOutput - suggested output file name
* @param mixed $sOption - upload or copy
*/
public function copyAndCreateThumb( $sDestDir, $mImgSrc, $sImgOutput, $sOption = null ){

// remember thumb size
$iOldSize = $this->iThumbY;

if( !is_dir( $sDestDir ) )
return null;

$sImgOutput = $this->throwNameOfFile( $sImgOutput );

$sImgOutput = $this->changeFileName( $sImgOutput );

if( $sOption == 'upload' ){
if( is_uploaded_file( $mImgSrc['tmp_name'] ) && is_file( $mImgSrc['tmp_name'] ) && filesize( $mImgSrc['tmp_name'] ) > 0 && $this->checkCorrectFile( $mImgSrc['name'], 'jpg|jpeg|gif|png' ) == 1 ){
$this->sExt = $this->throwExtOfFile( $mImgSrc['name'] );
$this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
$aNewFiles['bFile'] = $this->uploadFile( $mImgSrc, $sDestDir, $sImgOutput.$this->sExtDot );
}
else
return null;
}
elseif( $sOption == 'copy' ){
if( is_file( $mImgSrc ) && filesize( $mImgSrc ) > 0 && $this->checkCorrectFile( $mImgSrc, 'jpg|jpeg|gif|png' ) == 1 ){
$this->sExt = $this->throwExtOfFile( $mImgSrc );
$this->sExtDot = isset( $this->sExt ) ? '.'.$this->sExt : null;
$aNewFiles['bFile'] = $this->checkIsFile( $sImgOutput.$this->sExtDot, $sDestDir );
if( !copy( $mImgSrc, $sDestDir.$aNewFiles['bFile'] ) )
return null;
}
else
return null;
}
$sImgPatch = $sDestDir.$aNewFiles['bFile'];

$aNewFiles['bName'] = $this->throwNameOfFile( $aNewFiles['bFile'] );
$aNewFiles['sFile'] = $aNewFiles['bName'] . $this->iThumbAdd . '.' . $this->sExtDot;
$aImgSize = $this->throwImgSize( $sImgPatch );

if( defined( 'MAX_DIMENSION_OF_IMAGE' ) && ( $aImgSize['width'] > MAX_DIMENSION_OF_IMAGE || $aImgSize ['height'] > MAX_DIMENSION_OF_IMAGE ) ){
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){
$iOldAdd = $this->iThumbAdd;
$this->setThumbSize( MAX_DIMENSION_OF_IMAGE );
$this->setThumbAdd( '' );
$aNewFiles['bFile'] = $this->createThumb( $sImgPatch, $sDestDir, $aNewFiles['bFile'] );
$this->setThumbSize( $iOldSize );
$this->setThumbAdd( $iOldAdd );
}
else
return null;
}

if( $aImgSize['width'] >= $this->iThumbX || $aImgSize['height'] >= $this->iThumbX ){
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize )
$aNewFiles['sFile'] = $this->createThumb( $sImgPatch, $sDestDir );
else
return null;
}
else
copy( $sImgPatch, $sDestDir.$aNewFiles['sFile'] );

$aNewFiles['bWidth'] = $aImgSize['width'];
$aNewFiles['bHeight'] = $aImgSize['height'];
$aNewFiles['sWidth'] = $this->iThumbX;
$aNewFiles['sHeight'] = $this->iThumbY;
$aNewFiles['sName'] = basename( $aNewFiles['sFile'], '.'.$this->sExt );
$aNewFiles['ext'] = $this->sExt;

$this->iThumbY = 100;
$this->setThumbSize( $iOldSize );

return $aNewFiles;
} // end function copyAndCreateThumb

/**
* Clears propeties of object (set to default)
* @return void
*/
public function clearAll( ){
$this->iThumbX = 100;
$this->iThumbY = 100;
} // end function clearAll

/**
* Returns image size in px
* @return array/int
* @param string $imgSrc
* @param mixed $sOption
*/
public function throwImgSize( $imgSrc, $sOption = null ){
$aImg = getImageSize( $imgSrc );

$aImgSize['width'] = $aImg[0];
$aImgSize['height'] = $aImg[1];

if( $sOption == 'width' || $sOption == 'height' )
return $aImgSize[$sOption];
else
return $aImgSize;
} // end function throwImgSize

/**
* Returns image width in px
* @return int
* @param string $imgSrc
*/
public function throwImgWidth( $imgSrc ){
return $this->throwImgSize( $imgSrc, 'width' );
} // end function throwImgWidth

/**
* Returns image height in px
* @return int
* @param string $imgSrc
*/
public function throwImgHeight( $imgSrc ){
return $this->throwImgSize( $imgSrc, 'height' );
} // end function throwImgHeight


/**
* Creates new custom size thumb
* @return string
* @param string $sImgSource
* @param string $sImgDestDir
* @param int $iSize
* @param string $sImgOutput
* @param bool $bOverwrite
*/
public function createCustomThumb( $sImgSource, $sImgDestDir, $iSize = null, $sImgOutput = false, $bOverwrite = null ){

if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
return null;

$aImgSize = $this->throwImgSize( $sImgSource );
if( $aImgSize['width'] < $this->iMaxForThumbSize && $aImgSize ['height'] < $this->iMaxForThumbSize ){

$sImgExt = $this->throwExtOfFile( $sImgSource );

if( $sImgOutput == false )
$sImgOutput = $this->throwNameOfFile( $sImgSource ) . $this->sCustomThumbAdd . '.' . $sImgExt;

if( !isset( $bOverwrite ) )
$sImgOutput = $this->checkIsFile( $sImgOutput, $sImgDestDir );

$iOldSize = $this->iThumbX;
if( is_numeric( $iSize ) )
$this->setThumbSize( $iSize );
else
$this->setThumbSize( $this->iCustomThumbY );

$sFile = $this->createThumb( $sImgSource, $sImgDestDir, $sImgOutput );
$this->setThumbSize( $iOldSize );
return $sFile;
}
else
return null;
} // end function createCustomThumb


/**
* Function make photo thumbs
* @return int
* @param string $sImgSource - source file, from it thumb is created
* @param string $sImgDestDir - destination directory for thumb
* @param string $sImgOutput - picture name after change (default old name with _m addition)
* @param mixed $sOption - b/d
*/
public function createThumb( $sImgSource, $sImgDestDir, $sImgOutput = false, $iQuality = null, $sOption = null ) {

if( !is_dir( $sImgDestDir ) || $this->checkCorrectFile( $sImgSource, 'jpg|jpeg|gif|png' ) == 0 )
return null;

if( !is_numeric( $iQuality ) )
$iQuality = $this->iQuality;

$sImgExt = $this->throwExtOfFile( $sImgSource );

if( $sImgOutput == false )
$sImgOutput = basename( $sImgSource, '.'.$sImgExt ) . $this->iThumbAdd . '.' . $sImgExt;

$sImgOutput = $this->changeFileName( $sImgOutput );

$sImgBackup = $sImgDestDir.$sImgOutput . "_backup.jpg";
copy( $sImgSource, $sImgBackup );
$aImgProperties = GetImageSize( $sImgBackup );

if ( !$aImgProperties[2] == 2 ) {
return null;
}
else {
switch( $sImgExt ) {
case 'jpg':
$mImgCreate = ImageCreateFromJPEG( $sImgBackup );
break;
case 'jpeg':
$mImgCreate = ImageCreateFromJPEG( $sImgBackup );
break;
case 'png':
$mImgCreate = ImageCreateFromPNG( $sImgBackup );
break;
case 'gif':
$mImgCreate = ImageCreateFromGIF( $sImgBackup );
}

$iImgCreateX = ImageSX( $mImgCreate );
$iImgCreateY = ImageSY( $mImgCreate );

$iScaleY=$this->iThumbY/($iImgCreateY);
$this->iThumbX=$iImgCreateX*$iScaleY;

$iRatio = $this->iThumbX / $this->iThumbY;

if(

$this->iThumbX = ( int )( $this->iThumbX );
$this->iThumbY = ( int )( $this->iThumbY );


$mImgDest = imagecreatetruecolor( $this->iThumbX, $this->iThumbY );

if( $sImgExt == 'png' ){
imagealphablending( $mImgDest, false );
$iTransparent = imagecolorallocatealpha( $mImgDest, 0, 0, 0, 127 );
imagecolortransparent( $mImgDest, $iTransparent );
imagefill( $mImgDest, 0, 0, $iTransparent );
imagesavealpha( $mImgDest, true );
}
elseif ($sImgExt == 'gif'){
imagealphablending( $mImgDest, true );
imagesavealpha( $mImgDest, false );
$iBackgroundGif = imagecolorallocate( $mImgDest, $this->aBackgroundGif['red'], $this->aBackgroundGif['green'],$this->aBackgroundGif['blue'] );
imagefill( $mImgDest, 0, 0, $iBackgroundGif );
}

unlink( $sImgBackup );

if( function_exists( 'imagecopyresampled' ) )
$sCreateFunction = 'imagecopyresampled';
else
$sCreateFunction = 'imagecopyresized';

if( !$sCreateFunction( $mImgDest, $mImgCreate, 0, 0, 0, 0, $this->iThumbX + 1, $this->iThumbY + 1, $iImgCreateX, $iImgCreateY ) ) {
imagedestroy( $mImgCreate );
imagedestroy( $mImgDest );
return null;
}
else {
imagedestroy( $mImgCreate );
if( !is_file( $sImgDestDir.$sImgOutput ) ) {
touch( $sImgDestDir.$sImgOutput );
chmod( $sImgDestDir.$sImgOutput, 0666 );
}
switch( $sImgExt ) {
case 'jpg':
$Image = ImageJPEG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
break;
case 'jpeg':
$Image = ImageJPEG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
break;
case 'png':
$Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput );
break;
case 'gif':
if( function_exists( "imagegif" ) )
$Image = ImageGIF( $mImgDest, $sImgDestDir.$sImgOutput );
else{
if( $iQuality > 0 )
$iQuality = floor( ( $iQuality - 1 ) / 10 );
$Image = ImagePNG( $mImgDest, $sImgDestDir.$sImgOutput, $iQuality );
}
}
if ( $Image ) {
imagedestroy( $mImgDest );
return $sImgOutput;
}
imagedestroy( $mImgDest );
}
return null;
}

} // end function createThumb

};


?>

DonnaD

Avatar: DonnaD

2012-05-26 20:08

Mimo licznych prób, nie udało mi sie uzyskac porządanego efektu.... może jednak ktoś?

DonnaD

Avatar: DonnaD

2012-06-01 14:22

Chyba jednak będę "cieła" do rownych wielkosci wszystkie zdjęcia... nawet jeśli będą to portrety... Wczesniej tworzylam osobne zakladki do zdjęć portretów, ale szkoda miejsca..

Myslalam ze sobie ulatwię, ale nie wychodzi

Do góry
o nas | kontakt