If I understand correctly, do you want to replace the current image path with a new path, and such a path specifies a different size? I made a way here to replace the path, you can try to adapt to reach the conclusion.
Note that I am using a URL other than the one you specified, but the solution can be adapted as I said, I will show you how. My image is this:
<img src="http://www.rafaelalmeida.net78.net/exemplos/sopt/56952-src-img/100x150.png" class="thumb"/>
Note that it is in the name of the image that the size is specified, being "300x340.png" the image with another size. Well, come on.
Code
First we need to go through all the elements that have the class "Thumb", after that, take its current value that is in the attribute "src", so:
$("img.thumb").each(function() {
// Pega o caminho atual
var img_path = $(this).attr("src");
});
I thought it appropriate to use regex
to solve the problem, so I made one that takes the image size:
var regex = /rafaelalmeida.net78.net\/exemplos\/sopt\/56952-src-img\/(.+).png/;
Note that what is between the parentheses is the value to be caught, so in your case it would look like this:
var regex = /redir.com\?url=imgs.com\/img3356\/(.+)\/img.jpg/;
With regex in hand, we test if the image really meets the requirements, if yes, we take the value that regex returns and we check if it is the value you want to exchange (in your case "100x1500":
if (regex.test(img_path)) {
// Se o caminho da imagem bater com o regex...
// Especifica o tamanho atual
var size = img_path.match(regex)[1];
if (size == "100x150") {
// Se o tamanho for 100x150...
}
}
Now it’s simple, we replace the string that had the old value for the new using the same regex and finally change the value of src
to the new path:
// Substitui o antigo caminho com o novo tamanho
var new_path = img_path.replace(size, "300x340");
// Atribui o novo valor ao atributo "src"
$(this).attr("src", new_path);
Final code
With that we have our final code:
$(document).ready(function() {
// Percore todas as imagens com a classe "thumb"
$("img.thumb").each(function() {
// Pega o caminho atual
var img_path = $(this).attr("src");
// Define o regex
var regex = /rafaelalmeida.net78.net\/exemplos\/sopt\/56952-src-img\/(.+).png/;
if (regex.test(img_path)) {
// Se o caminho da imagem bater com o regex...
// Especifica o tamanho atual
var size = img_path.match(regex)[1];
if (size == "100x150") {
// Se o tamanho for 100x150...
// Substitui o antigo caminho com o novo tamanho
var new_path = img_path.replace(size, "300x340");
// Atribui o novo valor ao atributo "src"
$(this).attr("src", new_path);
}
}
});
});
Fiddle: http://jsfiddle.net/cmt60bqe/
I used two different addresses for the images, one with www and one without, to see that regex works with both.
I have the impression that even if some answer succeeds, the path chosen to solve the problem is far from ideal. Of course, without more details, it’s just a hunch.
– Bacco
And which way would you show me ?
– Carlos
Since I don’t know the details, it’s kind of complicated. What do you mean by "if the script doesn’t work"? If it’s for photo gallery or lightbox, it would be better to generate with the thumbnails Urls, and link to the large ones, right? (whereas you use PHP)
– Bacco
I’ll explain further: the page will have several images with defined sizes. But I want to change these sizes. Changing the url changes the size of the image. Then I made a schematic in php to do this for me. then the image url comes as a parameter of the php page address I used to do this. But I don’t want to use php unnecessarily, so I want a script that does that. But if javascript is disabled in the browser, it’s good to have the solution in php. I do not generate already with thumbnail urls because I am using the blogger platform, not accept php.
– Carlos
It is relatively simple to exchange the URLS for JS, but it will always be a patch. But if it is the only possible solution, we will wait for some answer then.
– Bacco
I saw that the only thing that stays static in the blogger’s image URL is their name. Then you could create a pattern in their name, for example: "100x150_nomeimg.png". This would be feasible?
– Rafael Almeida
I would, but it would depend on a manual action. There’s no way to take just by class ?
– Carlos