mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-16 12:20:09 -07:00
Improve Imagine image loaders
This commit is contained in:
parent
a6fab6c0be
commit
e5e50e8010
@ -8,6 +8,7 @@ set:
|
|||||||
minifigs: Minifigs
|
minifigs: Minifigs
|
||||||
rating: Rating
|
rating: Rating
|
||||||
reviews.link: View all reviews on Brickset.com
|
reviews.link: View all reviews on Brickset.com
|
||||||
|
image.alt: Image of set '%number%'
|
||||||
models:
|
models:
|
||||||
text: |
|
text: |
|
||||||
This set inventory has been obtained from Rebrickable.
|
This set inventory has been obtained from Rebrickable.
|
||||||
@ -69,6 +70,7 @@ model:
|
|||||||
aliases: Aliases
|
aliases: Aliases
|
||||||
download: Download brick
|
download: Download brick
|
||||||
empty: No model
|
empty: No model
|
||||||
|
image.alt: Image of brick '%number%'
|
||||||
form:
|
form:
|
||||||
search: Search
|
search: Search
|
||||||
category: Category
|
category: Category
|
||||||
@ -138,6 +140,7 @@ part:
|
|||||||
molds: Molds of part
|
molds: Molds of part
|
||||||
prints: Prints
|
prints: Prints
|
||||||
sets: Sets
|
sets: Sets
|
||||||
|
image.alt: Image of part '%number%'
|
||||||
|
|
||||||
form:
|
form:
|
||||||
search.submit: Search
|
search.submit: Search
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
{% set placeholder = asset("resources/images/transparent_min.png") %}
|
{% set placeholder = asset("resources/images/transparent_min.png") %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<img src="{{ placeholder }}" data-src="{{ asset(color~'/'~number~'.png') | imagine_filter(filter) }}" alt="{{ number }} - image">
|
<img src="{{ placeholder }}"
|
||||||
|
data-src="{{ asset(color~'/'~number) | imagine_filter(filter) }}"
|
||||||
|
alt="{{ 'part.image.alt'|trans({'%number%':number}) }}">
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
@ -18,7 +20,9 @@
|
|||||||
{% set placeholder = asset("resources/images/transparent_min.png") %}
|
{% set placeholder = asset("resources/images/transparent_min.png") %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<img src="{{ placeholder }}" data-src="{{ asset(number~'.jpg')|imagine_filter(filter) }}" alt="{{ number }} - image">
|
<img src="{{ placeholder }}"
|
||||||
|
data-src="{{ number|imagine_filter(filter) }}"
|
||||||
|
alt="{{ 'set.image.alt'|trans({'%number%':number}) }}">
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
@ -31,21 +31,25 @@ class PartImageLoader extends BaseImageLoader
|
|||||||
|
|
||||||
public function find($path)
|
public function find($path)
|
||||||
{
|
{
|
||||||
|
$localPath = '/images/'.$path.'.png';
|
||||||
|
|
||||||
// try to load image from local mediaFilesystem
|
// try to load image from local mediaFilesystem
|
||||||
if ($this->mediaFilesystem->has('/images/'.$path)) {
|
if ($this->mediaFilesystem->has($localPath)) {
|
||||||
return $this->mediaFilesystem->read('/images/'.$path);
|
return $this->mediaFilesystem->read($localPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rebrickablePath = $this->rebrickableContext.strtolower($path).'.png';
|
||||||
|
|
||||||
// try to load image from rebrickable website
|
// try to load image from rebrickable website
|
||||||
if ($this->remoteFileExists($this->rebrickableContext.$path)) {
|
if ($this->remoteFileExists($rebrickablePath)) {
|
||||||
$context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
|
$context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
|
||||||
|
|
||||||
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
|
return file_get_contents($rebrickablePath, false, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load part entity form rebrickable api and get image path from response
|
// Load part entity form rebrickable api and get image path from response
|
||||||
try {
|
try {
|
||||||
if (preg_match('/^(.*)\/(.*).png$/', $path, $match)) {
|
if (preg_match('/^(.*)\/(.*)$/', $path, $match)) {
|
||||||
$part = $this->rebrickableManager->getPart($match[2]);
|
$part = $this->rebrickableManager->getPart($match[2]);
|
||||||
|
|
||||||
if ($part && $part->getImgUrl()) {
|
if ($part && $part->getImgUrl()) {
|
||||||
|
@ -29,28 +29,28 @@ class SetImageLoader extends BaseImageLoader
|
|||||||
$this->mediaFilesystem = $mediaFilesystem;
|
$this->mediaFilesystem = $mediaFilesystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find($path)
|
public function find($setNumber)
|
||||||
{
|
{
|
||||||
|
$rebrickablePath = $this->rebrickableContext.strtolower($setNumber).'.jpg';
|
||||||
|
|
||||||
// try to load image from rebrickable website
|
// try to load image from rebrickable website
|
||||||
if ($this->remoteFileExists($this->rebrickableContext.strtolower($path))) {
|
if ($this->remoteFileExists($rebrickablePath)) {
|
||||||
$context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
|
$context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
|
||||||
|
|
||||||
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
|
return file_get_contents($rebrickablePath, false, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load part entity form brickset api and get image path from response
|
// Load part entity form brickset api and get image path from response
|
||||||
try {
|
try {
|
||||||
if (preg_match('/^(.*)(.png|.jpg)$/', $path, $match)) {
|
$set = $this->bricksetManager->getSetByNumber($setNumber);
|
||||||
$set = $this->bricksetManager->getSetByNumber($match[1]);
|
|
||||||
|
|
||||||
if ($set && $set->getImage()) {
|
if ($set && $set->getImage()) {
|
||||||
return file_get_contents($set->getImageURL());
|
return file_get_contents($set->getImageURL());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e);
|
throw new NotLoadableException(sprintf('Image %s could not be loaded.', $setNumber), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotLoadableException(sprintf('Source image %s not found.', $path));
|
throw new NotLoadableException(sprintf('Image %s not found.', $setNumber));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user