Last active
April 26, 2016 17:51
-
-
Save javimata/bbe59be6cbdb2791d6a40954f51ffef9 to your computer and use it in GitHub Desktop.
Archivo administrator/components/com_catalogo/models/producto.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function save($data) | |
{ | |
$app = JFactory::getApplication(); | |
$generaThumbs = JComponentHelper::getParams('com_catalogo')->get('generaThumbs'); | |
$ancho = JComponentHelper::getParams('com_catalogo')->get('anchoThumbs'); | |
if (isset($data['images']) && is_array($data['images'])) | |
{ | |
$images = $data['images']; | |
$images_array = array(); | |
$conteo_images = 1; | |
foreach ($images as $img => $im) { | |
if ($im){ | |
$images_array['image_'.$conteo_images] = $im; | |
if ($generaThumbs==1): | |
$ancho = JComponentHelper::getParams('com_catalogo')->get('anchoThumbs'); | |
$JImage = new JImage(JPATH_SITE . "/". $im); | |
$properties = JImage::getImageFileProperties(JPATH_SITE . "/". $im); | |
$resizedImage = $JImage->resize($ancho, $ancho, true); | |
$mime = $properties->mime; | |
if ($mime == 'image/jpeg') | |
{ | |
$type = IMAGETYPE_JPEG; | |
$ext = "jpg"; | |
} | |
elseif ($mime == 'image/png') | |
{ | |
$type = IMAGETYPE_PNG; | |
$ext = "png"; | |
} | |
elseif ($mime == 'image/gif') | |
{ | |
$type = IMAGETYPE_GIF; | |
$ext = "gif"; | |
} | |
$resizedImage->toFile(JPATH_SITE . "/images/thumbs/".md5($data['id']) . "-" . $conteo_images . "." .$ext, $type); | |
endif; | |
$conteo_images++; | |
} | |
} | |
$data['images'] = json_encode($images_array); | |
} | |
// Thumbs campo imagen descripcion | |
if (isset($data['imagen_descripcion']) && $data['imagen_descripcion'] != "" ){ | |
$JImagen = new JImage(JPATH_SITE . "/". $data['imagen_descripcion']); | |
$properties = JImage::getImageFileProperties(JPATH_SITE . "/". $data['imagen_descripcion']); | |
$resizedImage = $JImagen->resize('200', '200', true); | |
$mime = $properties->mime; | |
if ($mime == 'image/jpeg') | |
{ | |
$type = IMAGETYPE_JPEG; | |
$ext = "jpg"; | |
} | |
elseif ($mime == 'image/png') | |
{ | |
$type = IMAGETYPE_PNG; | |
$ext = "png"; | |
} | |
elseif ($mime == 'image/gif') | |
{ | |
$type = IMAGETYPE_GIF; | |
$ext = "gif"; | |
} | |
$resizedImage->toFile(JPATH_SITE . "/images/thumbs/".md5($data['id']) . "." .$ext, $type); | |
} | |
if (parent::save($data)) | |
{ | |
return true; | |
} | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function save($data) | |
{ | |
$app = JFactory::getApplication(); | |
if (isset($data['images']) && is_array($data['images'])) | |
{ | |
$registry = new JRegistry; | |
$registry->loadArray($data['images']); | |
$data['images'] = (string) $registry; | |
foreach ($data['images'] as $img) { | |
$JImage = new JImage($img); | |
$size_thumb = '150x150'; | |
$JImage->createThumbs($size_thumb,1); | |
} | |
} | |
if (parent::save($data)) | |
{ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
En la base de datos tengo 3 tipos de imagen:
1 Imagen principal
Campo imagen
2 Grupo de imágenes fields / field image1, image2... image5
Campo Array images
3 Imagen de listados
Campo imagen_listado
La idea es que, pueda configurar un tamaño para cada una desde el config del componente; por ejemplo:
imagen - no se modifique (quizá la omita en un futuro)
images - tamaño original, tamaño slider (400x300 con crop), imagen thumb (150x150 con crop)
imagen_listado - tamaño original, thumb 200x200
En el código de Gists puse lo que tengo ahora pero obvio no funciona :-(
No se si es ahi donde deba usar el JIMAGE o en otro lado, o obvio, no se si este correcto así, supongo que no.
Lo que actualmente no funciona es la creación de los thumbs, es decir, el foreach con el createThumbs
De ser posible, me gustaría (mucho) guardar los thumbs con un nombre definido, tipo md5($item->id) . "_XS." . $extension